Exemple #1
0
 /**
  * Generates thumbnail.
  *
  * Main plugin routine, which creates thumbnail for given image using manager options
  * (module, preset, transformation etc.)
  *
  * @param string    $imagePath  Path to source image
  * @param string    $objectId   Object identifier (for example ID)
  *
  * @return string Thumbnail path, source image path (if thumbnail generation failed, empty string if image is not readable)
  */
 public function getThumb($imagePath, $objectId = null)
 {
     if (!is_readable($imagePath)) {
         return $imagePath;
     }
     if (!is_string($objectId)) {
         $objectId = $this->getObjectId($imagePath);
     }
     $thumbDir = $this->getFullThumbDir($objectId, $imagePath);
     $preset = $this->getPreset();
     $image = new SystemPlugin_Imagine_Image($imagePath, $thumbDir, $preset->getName(), $preset['extension']);
     if (!$image->hasThumb()) {
         try {
             $this->removePresetThumbs($imagePath, $objectId)->createThumbnail($image, $preset);
         } catch (Exception $e) {
             //! %1$s is source image path, %2$s is error message
             LogUtil::log($this->__f('An error occurred during thumbnail creation for image [%1$s]. Error details: %2$s', array($imagePath, $e->getMessage())), \Monolog\Logger::INFO);
             return $imagePath;
         }
     }
     return str_replace(realpath('.') . '/', '', $image->getThumbPathname());
 }