Exemplo 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];
 }
Exemplo 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]]);
 }