コード例 #1
0
ファイル: LegacyResizer.php プロジェクト: contao/core-bundle
 /**
  * {@inheritdoc}
  */
 protected function executeResize(ImageInterface $image, ResizeCoordinatesInterface $coordinates, $path, ResizeOptionsInterface $options)
 {
     if (isset($GLOBALS['TL_HOOKS']['getImage']) && is_array($GLOBALS['TL_HOOKS']['getImage']) && $this->legacyImage) {
         foreach ($GLOBALS['TL_HOOKS']['getImage'] as $callback) {
             $return = System::importStatic($callback[0])->{$callback[1]}($this->legacyImage->getOriginalPath(), $this->legacyImage->getTargetWidth(), $this->legacyImage->getTargetHeight(), $this->legacyImage->getResizeMode(), $this->legacyImage->getCacheName(), new File($this->legacyImage->getOriginalPath()), $this->legacyImage->getTargetPath(), $this->legacyImage);
             if (is_string($return)) {
                 return $this->createImage($image, TL_ROOT . '/' . $return);
             }
         }
     }
     if ($image->getImagine() instanceof GdImagine) {
         /** @var Config $config */
         $config = $this->framework->getAdapter(Config::class);
         $dimensions = $image->getDimensions();
         // Return the path to the original image if it cannot be handled
         if ($dimensions->getSize()->getWidth() > $config->get('gdMaxImgWidth') || $dimensions->getSize()->getHeight() > $config->get('gdMaxImgHeight') || $coordinates->getSize()->getWidth() > $config->get('gdMaxImgWidth') || $coordinates->getSize()->getHeight() > $config->get('gdMaxImgHeight')) {
             return $this->createImage($image, $image->getPath());
         }
     }
     return parent::executeResize($image, $coordinates, $path, $options);
 }
コード例 #2
0
ファイル: Resizer.php プロジェクト: contao/image
 /**
  * Creates the target cache path.
  *
  * @param string                     $path
  * @param ResizeCoordinatesInterface $coordinates
  *
  * @return string The realtive target path
  */
 private function createCachePath($path, ResizeCoordinatesInterface $coordinates)
 {
     $pathinfo = pathinfo($path);
     $hash = substr(md5(implode('|', [$path, filemtime($path), $coordinates->getHash()])), 0, 9);
     return substr($hash, 0, 1) . '/' . $pathinfo['filename'] . '-' . substr($hash, 1) . '.' . $pathinfo['extension'];
 }