Ejemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function getImage($relativePath, $filter)
 {
     $eventManager = $this->getEventManager();
     $eventManager->trigger(__FUNCTION__, $this, ['relativePath' => $relativePath, 'filter' => $filter]);
     $filterOptions = $this->filterManager->getFilterOptions($filter);
     $binary = $this->loaderManager->loadBinary($relativePath, $filter);
     if (isset($filterOptions['format'])) {
         $format = $filterOptions['format'];
     } else {
         $format = $binary->getFormat() ?: 'png';
     }
     $imageOutputOptions = [];
     if (isset($filterOptions['quality'])) {
         $imageOutputOptions['quality'] = $filterOptions['quality'];
     }
     if ($format === 'gif' && $filterOptions['animated']) {
         $imageOutputOptions['animated'] = $filterOptions['animated'];
     }
     if ($this->cacheManager->isCachingEnabled($filter, $filterOptions) && $this->cacheManager->cacheExists($relativePath, $filter, $format)) {
         $imagePath = $this->cacheManager->getCachePath($relativePath, $filter, $format);
         $filteredImage = $this->imagine->open($imagePath);
     } else {
         $image = $this->imagine->load($binary->getContent());
         $filteredImage = $this->filterManager->getFilter($filter)->apply($image);
         if ($this->cacheManager->isCachingEnabled($filter, $filterOptions)) {
             $this->cacheManager->createCache($relativePath, $filter, $filteredImage, $format, $imageOutputOptions);
         }
     }
     $args = ['relativePath' => $relativePath, 'filter' => $filter, 'filteredImage' => $filteredImage, 'format' => $format];
     $eventManager->trigger(__FUNCTION__ . '.post', $this, $args);
     return ['image' => $filteredImage, 'format' => $format, 'imageOutputOptions' => $imageOutputOptions];
 }
Ejemplo n.º 2
0
 /**
  * Gets url of image
  *
  * @param  string $relativeName Relative Path
  * @param  string $filter       Filter Service
  * @return string
  */
 public function __invoke($relativeName, $filter)
 {
     $filterOptions = $this->filterManager->getFilterOptions($filter);
     if (isset($filterOptions['format'])) {
         $format = $filterOptions['format'];
     } else {
         $binary = $this->loaderManager->loadBinary($relativeName, $filter);
         $format = $binary->getFormat() ?: 'png';
     }
     if ($this->cacheManager->isCachingEnabled($filter, $filterOptions) && $this->cacheManager->cacheExists($relativeName, $filter, $format)) {
         $basePathHelper = $this->getView()->plugin('basePath');
         return $basePathHelper() . '/' . $this->cacheManager->getCacheUrl($relativeName, $filter, $format);
     }
     $urlHelper = $this->getView()->plugin('url');
     return $urlHelper('htimg/display', ['filter' => $filter], ['query' => ['relativePath' => $relativeName]]);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritDoc}
  */
 public function loadBinary($relativePath, $filter)
 {
     $filterOptions = $this->filterManager->getFilterOptions($filter);
     if (isset($filterOptions['image_loader'])) {
         $imageLoader = $filterOptions['image_loader'];
     } else {
         $imageLoader = $this->defaultImageLoader;
     }
     if (!is_object($imageLoader)) {
         $imageLoader = $this->imageLoaders->get($imageLoader, isset($filterOptions['loader_options']) ? $filterOptions['loader_options'] : []);
     }
     $binary = $imageLoader->load($relativePath);
     if (!$binary) {
         throw new Exception\ImageNotFoundException();
     }
     if (!$binary instanceof BinaryInterface) {
         $binary = new Binary($binary, $this->mimeTypeGuesser->guess($binary));
     }
     if ($binary->getFormat() === null) {
         $binary->setFormat($this->getExtensionGuesser()->guess($binary->getMimeType()));
     }
     return $binary;
 }