/** * {@inheritdoc} */ public function getCacheName() { $strFallbackFormat = \Config::get('magickimages_fallback_extension') ?: 'jpg'; if (!in_array($this->fileObj->extension, ['jpg', 'png', 'gif'])) { // Change file suffix return substr(parent::getCacheName(), 0, -strlen($this->fileObj->extension)) . $strFallbackFormat; } return parent::getCacheName(); }
/** * {@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); }
/** * Tests the getCacheName() method. * * @param array $arguments * @param string $expectedCacheName * * @dataProvider getCacheName */ public function testGetCacheName($arguments, $expectedCacheName) { /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileMock */ $fileMock = $this->getMockBuilder('Contao\\File')->setMethods(['__get', 'exists'])->setConstructorArgs(['dummy.jpg'])->getMock(); $fileMock->expects($this->any())->method('exists')->will($this->returnValue(true)); $fileMock->expects($this->any())->method('__get')->will($this->returnCallback(function ($key) use($arguments) { switch ($key) { case 'extension': return 'jpg'; case 'path': return $arguments[2]; case 'filename': return $arguments[2]; case 'mtime': return $arguments[5]; case 'width': case 'viewWidth': return 200; case 'height': case 'viewHeight': return 200; default: return null; } })); $imageObj = new Image($fileMock); $imageObj->setTargetWidth($arguments[0]); $imageObj->setTargetHeight($arguments[1]); $imageObj->setResizeMode($arguments[3]); $imageObj->setZoomLevel($arguments[4]); $imageObj->setImportantPart($arguments[6]); $this->assertSame($imageObj->getCacheName(), $expectedCacheName); }