/** * {@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 setters and getters. */ public function testSettersAndGetters() { /** @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) { switch ($key) { case 'extension': return 'jpg'; case 'path': return 'dummy.jpg'; case 'width': case 'viewWidth': return 100; case 'height': case 'viewHeight': return 100; default: return null; } })); $imageObj = new Image($fileMock); $this->assertFalse($imageObj->getForceOverride()); $imageObj->setForceOverride(true); $this->assertTrue($imageObj->getForceOverride()); $this->assertSame($imageObj->getImportantPart(), ['x' => 0, 'y' => 0, 'width' => 100, 'height' => 100]); $imageObj->setImportantPart(['x' => 20, 'y' => 40, 'width' => 80, 'height' => 60]); $this->assertSame($imageObj->getImportantPart(), ['x' => 20, 'y' => 40, 'width' => 80, 'height' => 60]); $imageObj->setImportantPart(['x' => -20, 'y' => 40.1, 'width' => '80', 'height' => 120]); $this->assertSame($imageObj->getImportantPart(), ['x' => 0, 'y' => 40, 'width' => 80, 'height' => 60]); $imageObj->setImportantPart(['x' => 200, 'y' => 200, 'width' => 200, 'height' => 200]); $this->assertSame($imageObj->getImportantPart(), ['x' => 99, 'y' => 99, 'width' => 1, 'height' => 1]); $imageObj->setImportantPart(null); $this->assertSame($imageObj->getImportantPart(), ['x' => 0, 'y' => 0, 'width' => 100, 'height' => 100]); $this->assertSame($imageObj->getTargetHeight(), 0); $imageObj->setTargetHeight(20); $this->assertSame($imageObj->getTargetHeight(), 20); $imageObj->setTargetHeight(50.125); $this->assertSame($imageObj->getTargetHeight(), 50); $this->assertSame($imageObj->getTargetWidth(), 0); $imageObj->setTargetWidth(20); $this->assertSame($imageObj->getTargetWidth(), 20); $imageObj->setTargetWidth(50.125); $this->assertSame($imageObj->getTargetWidth(), 50); $this->assertSame($imageObj->getTargetPath(), ''); $imageObj->setTargetPath('foobar'); $this->assertSame($imageObj->getTargetPath(), 'foobar'); $this->assertSame($imageObj->getZoomLevel(), 0); $imageObj->setZoomLevel(54); $this->assertSame($imageObj->getZoomLevel(), 54); $this->assertSame($imageObj->getResizeMode(), 'crop'); $imageObj->setResizeMode('foobar'); $this->assertSame($imageObj->getResizeMode(), 'foobar'); $this->assertSame($imageObj->getOriginalPath(), 'dummy.jpg'); $this->assertSame($imageObj->getResizedPath(), ''); }