/**
  * Returns metadata for an asset.
  *
  * @param AssetFileModel $asset    The asset model to parse
  * @param string         $property String in dot notation that sets the root metadata property
  *
  * @return array|string The asset's metadata
  */
 public function getAssetMetadata($asset, $property = null)
 {
     $getId3 = $this->_getGetId3();
     if (!$asset instanceof AssetFileModel) {
         throw new Exception('(Asset Metadata) The plugin only works with asset models.');
     }
     $sourceType = craft()->assetSources->getSourceTypeById($asset->sourceId);
     if ($sourceType->isRemote()) {
         $config = craft()->config->get('remoteAssetSources', 'assetmetadata');
         // Makes a local copy of the file if it's from a remote source.
         $path = AssetsHelper::getTempFilePath($asset->getExtension());
         $this->_downloadRemoteFile($asset->getUrl(), $path, $config['downloadSize']);
         // Pad truncated file to original size.
         if ($config['padTruncatedFiles'] && $config['downloadSize'] && $asset->size > $config['downloadSize']) {
             $this->_padFile($path, $asset->size - $config['downloadSize']);
         }
         $metadata = $getId3->analyze($path);
         IOHelper::deleteFile($path);
     } else {
         $path = $sourceType->getImageSourcePath($asset);
         $metadata = $getId3->analyze($path);
     }
     // Merges ID3 tags and stores them in a "comments" property.
     getid3_lib::CopyTagsToComments($metadata);
     // Removes troublesome properties.
     $this->_removeProperties($metadata);
     return $this->_getValueByKey($property, $metadata);
 }
 /**
  * Transform
  *
  * @param AssetFileModel $element Asset
  *
  * @return array Asset
  */
 public function transform(AssetFileModel $element)
 {
     return ['id' => (int) $element->id, 'enabled' => (bool) $element->enabled, 'archived' => (bool) $element->archived, 'locale' => $element->locale, 'localeEnabled' => (bool) $element->localeEnabled, 'slug' => $element->slug, 'url' => $element->getUrl(), 'title' => $element->title, 'extension' => $element->getExtension(), 'mime' => $element->getMimeType(), 'dateCreated' => $element->dateCreated, 'dateUpdated' => $element->dateUpdated, 'root' => $element->root ? (int) $element->root : null, 'lft' => $element->lft ? (int) $element->lft : null, 'rgt' => $element->rgt ? (int) $element->rgt : null, 'level' => $element->level ? (int) $element->level : null, 'sourceId' => (int) $element->sourceId, 'folderId' => (int) $element->folderId, 'originalName' => $element->originalName, 'kind' => $element->kind, 'width' => (int) $element->width, 'height' => (int) $element->height, 'size' => (int) $element->size, 'dateModified' => $element->dateModified];
 }
 protected function getImageQuality(AssetFileModel $asset, $quality = null)
 {
     $desiredQuality = !$quality ? 100 : $quality;
     if ($asset->getExtension() == 'png') {
         // Valid PNG quality settings are 0-9, so normalize and flip, because we're talking about compression
         // levels, not quality, like jpg and gif.
         $quality = round($desiredQuality * 9 / 100);
         $quality = 9 - $quality;
         if ($quality < 0) {
             $quality = 0;
         }
         if ($quality > 9) {
             $quality = 9;
         }
     } else {
         $quality = $desiredQuality;
     }
     return $quality;
 }