diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php index 867cb8c..3339623 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php @@ -81,7 +81,7 @@ protected function validateArguments(ImageInterface $image, array $arguments) { /** * {@inheritdoc} */ - protected function execute(ImageInterface $image, array $arguments) { + protected function execute(ImageInterface $image, array $arguments) { $res = $this->getToolkit()->createTmp($this->getToolkit()->getType(), $arguments['width'], $arguments['height']); if (!imagecopyresampled($res, $this->getToolkit()->getResource(), 0, 0, $arguments['x'], $arguments['y'], $arguments['width'], $arguments['height'], $arguments['width'], $arguments['height'])) { diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php index a8d1b9f..ed71ecf 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Desaturate.php @@ -35,7 +35,7 @@ protected function arguments() { /** * {@inheritdoc} */ - protected function execute(ImageInterface $image, array $arguments) { + protected function execute(ImageInterface $image, array $arguments) { // PHP installations using non-bundled GD do not have imagefilter. if (!function_exists('imagefilter')) { watchdog('image', 'The image %file could not be desaturated because the imagefilter() function is not available in this PHP installation.', array('%file' => $image->getSource())); diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php index a517b40..0f55de8 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php @@ -60,7 +60,7 @@ protected function validateArguments(ImageInterface $image, array $arguments) { /** * {@inheritdoc} */ - protected function execute(ImageInterface $image, array $arguments = array()) { + protected function execute(ImageInterface $image, array $arguments = array()) { $res = $this->getToolkit()->createTmp($this->getToolkit()->getType(), $arguments['width'], $arguments['height']); if (!imagecopyresampled($res, $this->getToolkit()->getResource(), 0, 0, 0, 0, $arguments['width'], $arguments['height'], $this->getToolkit()->getWidth($image), $this->getToolkit()->getHeight($image))) { diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php index 6a8dbf2..b0fa039 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php @@ -43,7 +43,7 @@ protected function arguments() { /** * {@inheritdoc} */ - protected function execute(ImageInterface $image, array $arguments) { + protected function execute(ImageInterface $image, array $arguments) { // PHP installations using non-bundled GD do not have imagerotate. if (!function_exists('imagerotate')) { watchdog('image', 'The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', array('%file' => $image->getSource())); diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php index 1d0fc6e..82c03ff 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php @@ -83,10 +83,16 @@ protected function validateArguments(ImageInterface $image, array $arguments) { return $arguments; } + /** + * {@inheritdoc} + */ protected function execute(ImageInterface $image, array $arguments = array()) { - // Don't upscale if the option isn't enabled. - if ($arguments['upscale'] || ($arguments['width'] <= $this->getToolkit()->getWidth($image) && $arguments['height'] <= $this->getToolkit()->getHeight($image))) { - return parent::execute($image, $arguments); + // Don't scale if we don't change the dimensions at all. + if ($arguments['width'] !== $this->getToolkit()->getWidth($image) || $arguments['height'] !== $this->getToolkit()->getHeight($image)) { + // Don't upscale if the option isn't enabled. + if ($arguments['upscale'] || ($arguments['width'] <= $this->getToolkit()->getWidth($image) && $arguments['height'] <= $this->getToolkit()->getHeight($image))) { + return parent::execute($image, $arguments); + } } return TRUE; } diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php index da8da00..18f48f4 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php @@ -60,7 +60,7 @@ protected function validateArguments(ImageInterface $image, array $arguments) { /** * {@inheritdoc} */ - protected function execute(ImageInterface $image, array $arguments = array()) { + protected function execute(ImageInterface $image, array $arguments = array()) { return $this->getToolkit()->apply('resize', $image, $arguments['resize']) && $this->getToolkit()->apply('crop', $image, $arguments); } diff --git a/core/tests/Drupal/Tests/Core/Image/ImageTest.php b/core/tests/Drupal/Tests/Core/Image/ImageTest.php index 9704855..058e222 100644 --- a/core/tests/Drupal/Tests/Core/Image/ImageTest.php +++ b/core/tests/Drupal/Tests/Core/Image/ImageTest.php @@ -91,8 +91,9 @@ protected function getToolkitMock(array $stubs = array()) { * @return \PHPUnit_Framework_MockObject_MockObject */ protected function getToolkitOperationMock($class_name, ImageToolkitInterface $toolkit) { - $mock_builder = $this->getMockBuilder('Drupal\\system\\Plugin\\ImageToolkit\\Operation\\gd\\' . $class_name); + $mock_builder = $this->getMockBuilder('Drupal\system\Plugin\ImageToolkit\Operation\gd\\' . $class_name); return $mock_builder + ->setMethods(array('execute')) ->setConstructorArgs(array(array(), '', array(), $toolkit)) ->getMock(); } @@ -263,7 +264,7 @@ public function testParseFileFails() { public function testScaleWidth() { $this->getTestImageForOperation('Scale'); $this->toolkitOperation->expects($this->once()) - ->method('apply') + ->method('execute') ->will($this->returnArgument(1)); $ret = $this->image->apply('scale', array('width' => 44, 'upscale' => FALSE)); @@ -276,7 +277,7 @@ public function testScaleWidth() { public function testScaleHeight() { $this->getTestImageForOperation('Scale'); $this->toolkitOperation->expects($this->once()) - ->method('apply') + ->method('execute') ->will($this->returnArgument(1)); $ret = $this->image->apply('scale', array('height' => 50, 'upscale' => FALSE)); @@ -289,10 +290,13 @@ public function testScaleHeight() { public function testScaleSame() { $this->getTestImageForOperation('Scale'); // Dimensions are the same, resize should not be called. - $this->toolkitOperation->expects($this->never()) - ->method('apply'); + $this->toolkitOperation->expects($this->once()) + ->method('execute') + ->will($this->returnArgument(1)); $ret = $this->image->apply('scale', array ('width' => 88, 'height' => 100, 'upscale' => FALSE)); + $this->assertEquals(88, $ret['width']); + $this->assertEquals(100, $ret['height']); } /** @@ -301,7 +305,7 @@ public function testScaleSame() { public function testScaleAndCropWidth() { $this->getTestImageForOperation('ScaleAndCrop'); $this->toolkitOperation->expects($this->once()) - ->method('apply') + ->method('execute') ->will($this->returnArgument(1)); $ret = $this->image->apply('scale_and_crop', array ('width' => 34, 'height' => 50, 'upscale' => FALSE)); @@ -314,7 +318,7 @@ public function testScaleAndCropWidth() { public function testScaleAndCropHeight() { $this->getTestImageForOperation('ScaleAndCrop'); $this->toolkitOperation->expects($this->once()) - ->method('apply') + ->method('execute') ->will($this->returnArgument(1)); $ret = $this->image->apply('scale_and_crop', array ('width' => 44, 'height' => 40)); @@ -327,7 +331,7 @@ public function testScaleAndCropHeight() { public function testScaleAndCropFails() { $this->getTestImageForOperation('ScaleAndCrop'); $this->toolkitOperation->expects($this->once()) - ->method('apply') + ->method('execute') ->will($this->returnArgument(1)); $ret = $this->image->apply('scale_and_crop', array('width' => 44, 'height' => 40)); @@ -343,7 +347,7 @@ public function testScaleAndCropFails() { public function testCropWidth() { $this->getTestImageForOperation('Crop'); $this->toolkitOperation->expects($this->once()) - ->method('apply') + ->method('execute') ->will($this->returnArgument(1)); // Cropping with width only should preserve the aspect ratio. @@ -357,7 +361,7 @@ public function testCropWidth() { public function testCropHeight() { $this->getTestImageForOperation('Crop'); $this->toolkitOperation->expects($this->once()) - ->method('apply') + ->method('execute') ->will($this->returnArgument(1)); // Cropping with height only should preserve the aspect ratio. @@ -371,7 +375,7 @@ public function testCropHeight() { public function testCrop() { $this->getTestImageForOperation('Crop'); $this->toolkitOperation->expects($this->once()) - ->method('apply') + ->method('execute') ->will($this->returnArgument(1)); $ret = $this->image->apply('crop', array ('x' => 0, 'y' => 0, 'width' => 44, 'height' => 50)); @@ -384,7 +388,7 @@ public function testCrop() { public function testResize() { $this->getTestImageForOperation('Resize'); $this->toolkitOperation->expects($this->once()) - ->method('apply') + ->method('execute') ->will($this->returnArgument(1)); // Resize with integer for width and height. @@ -399,7 +403,7 @@ public function testResize() { public function testFloatResize() { $this->getTestImageForOperation('Resize'); $this->toolkitOperation->expects($this->once()) - ->method('apply') + ->method('execute') ->will($this->returnArgument(1)); // Pass a float for width. @@ -414,7 +418,7 @@ public function testFloatResize() { public function testDesaturate() { $this->getTestImageForOperation('Desaturate'); $this->toolkitOperation->expects($this->once()) - ->method('apply') + ->method('execute') ->will($this->returnArgument(1)); $this->image->apply('desaturate'); @@ -426,7 +430,7 @@ public function testDesaturate() { public function testRotate() { $this->getTestImageForOperation('Rotate'); $this->toolkitOperation->expects($this->once()) - ->method('apply') + ->method('execute') ->will($this->returnArgument(1)); $ret = $this->image->apply('rotate', array('degrees' => 90));