/**
  * Get paths for a local asset
  *
  * @param AssetFileModel $image
  */
 private function _getPathsForLocalAsset(AssetFileModel $image)
 {
     $assetSourcePath = craft()->config->parseEnvironmentString($image->getSource()->settings['url']);
     if (strrpos($assetSourcePath, 'http') !== false) {
         $parsedUrl = parse_url($assetSourcePath);
         $assetSourcePath = $parsedUrl['path'];
     }
     $this->sourcePath = ImagerService::fixSlashes(craft()->config->parseEnvironmentString($image->getSource()->settings['path']) . $image->getFolder()->path);
     $this->targetPath = ImagerService::fixSlashes(craft()->imager->getSetting('imagerSystemPath') . $assetSourcePath . $image->getFolder()->path) . $image->id . '/';
     $this->targetUrl = craft()->imager->getSetting('imagerUrl') . ImagerService::fixSlashes($assetSourcePath . $image->getFolder()->path, true) . $image->id . '/';
     $this->sourceFilename = $this->targetFilename = $image->filename;
 }
 /**
  * Gets a file by its asset.
  *
  * @param AssetFileModel $asset
  *
  * @return string
  */
 protected function getAssetFile(AssetFileModel $asset)
 {
     // Check if we have this filenname cached already
     if (!isset($this->assets[$asset->id])) {
         // Get asset source
         $source = $asset->getSource();
         // Get asset source type
         $sourceType = $source->getSourceType();
         // Get asset file
         $this->assets[$asset->id] = $sourceType->getLocalCopy($asset);
     }
     return $this->assets[$asset->id];
 }
 /**
  * Detect the auto web-safe format for the Assets file. Returns null, if the file is not an image.
  *
  * @param AssetFileModel $file
  *
  * @return mixed|string
  * @throws Exception
  */
 public function detectAutoTransformFormat(AssetFileModel $file)
 {
     if (in_array(mb_strtolower($file->getExtension()), ImageHelper::getWebSafeFormats())) {
         return $file->getExtension();
     } else {
         if ($file->kind == "image") {
             // The only reasonable way to check for transparency is with Imagick. If Imagick is not present, then
             // we fallback to jpg
             if (craft()->images->isGd() || !method_exists("Imagick", "getImageAlphaChannel")) {
                 return 'jpg';
             }
             $source = craft()->assetSources->populateSourceType($file->getSource());
             $localCopy = $source->getLocalCopy($file);
             $image = craft()->images->loadImage($localCopy);
             if ($image->isTransparent()) {
                 $format = 'png';
             } else {
                 $format = 'jpg';
             }
             if ($source->isRemote()) {
                 // Store for potential later use and queue for deletion if needed.
                 $file->setTransformSource($localCopy);
                 $this->queueSourceForDeletingIfNecessary($localCopy);
             } else {
                 // For local, though, we just delete the temp file.
                 IOHelper::deleteFile($localCopy);
             }
             return $format;
         }
     }
     throw new Exception(Craft::t("Tried to detect the appropriate image format for a non-image!"));
 }
 /**
  * @param AssetFileModel $asset
  *
  * @return string
  */
 protected function getAssetFilePath(AssetFileModel $asset)
 {
     return $asset->getSource()->getSourceType()->getBasePath() . $asset->getFolder()->path . $asset->filename;
 }