diff --git a/core/modules/image/src/Entity/ImageStyle.php b/core/modules/image/src/Entity/ImageStyle.php index 6dc7ada..0aea62d 100644 --- a/core/modules/image/src/Entity/ImageStyle.php +++ b/core/modules/image/src/Entity/ImageStyle.php @@ -312,7 +312,7 @@ public function transformDimensions(array &$dimensions) { */ public function getDerivativeExtension($extension) { foreach ($this->getEffects() as $effect) { - $effect->getDerivativeExtension($extension); + $extension = $effect->getDerivativeExtension($extension); } return $extension; } @@ -437,9 +437,8 @@ protected function getHashSalt() { * path with the added extension if it does. */ protected function addExtension($path) { - $extension = pathinfo($path, PATHINFO_EXTENSION); - $original_extension = $extension; - $extension = $this->getDerivativeExtension($extension); + $original_extension = pathinfo($path, PATHINFO_EXTENSION); + $extension = $this->getDerivativeExtension($original_extension); if ($original_extension !== $extension) { $path .= '.' . $extension; } diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php index 052bad9..473972f 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php @@ -371,7 +371,7 @@ public static function getSupportedExtensions() { /** * Returns the IMAGETYPE_xxx constant for the given extension. * - * This is the reverse of the @see image_type_to_extension() function. + * This is the reverse of the image_type_to_extension() function. * * @param string $extension * The extension to get the IMAGETYPE_xxx constant for. @@ -379,10 +379,12 @@ public static function getSupportedExtensions() { * @return int * The IMAGETYPE_xxx constant for the given extension, or IMAGETYPE_UNKNOWN * for unsupported extensions. + * + * @see image_type_to_extension() */ public function extensionToImageType($extension) { foreach ($this->supportedTypes() as $type) { - if (image_type_to_extension($type) === $extension) { + if (image_type_to_extension($type, FALSE) === $extension) { return $type; } } diff --git a/core/modules/system/src/Tests/Image/ToolkitGdTest.php b/core/modules/system/src/Tests/Image/ToolkitGdTest.php index 40a8691..4639e42 100644 --- a/core/modules/system/src/Tests/Image/ToolkitGdTest.php +++ b/core/modules/system/src/Tests/Image/ToolkitGdTest.php @@ -261,6 +261,7 @@ function testManipulations() { $this->fail(String::format('Could not load image %file.', array('%file' => $file))); continue 2; } + $image_original_type = $image->getToolkit()->getType(); // All images should be converted to truecolor when loaded. $image_truecolor = imageistruecolor($toolkit->getResource()); @@ -312,8 +313,9 @@ function testManipulations() { $this->assertTrue($correct_dimensions_real, String::format('Image %file after %action action has proper dimensions.', array('%file' => $file, '%action' => $op))); $this->assertTrue($correct_dimensions_object, String::format('Image %file object after %action action is reporting the proper height and width values.', array('%file' => $file, '%action' => $op))); - // JPEG colors will always be messed up due to compression. - if ($image->getToolkit()->getType() != IMAGETYPE_JPEG) { + // JPEG colors will always be messed up due to compression. So we skip + // these tests if the original or the result is in jpeg format. + if ($image->getToolkit()->getType() != IMAGETYPE_JPEG && $image_original_type != IMAGETYPE_JPEG) { // Now check each of the corners to ensure color correctness. foreach ($values['corners'] as $key => $corner) { // The test gif that does not have transparency has yellow where the @@ -341,8 +343,13 @@ function testManipulations() { break; } $color = $this->getPixelColor($image, $x, $y); - $correct_colors = $this->colorsAreEqual($color, $corner); - $this->assertTrue($correct_colors, String::format('Image %file object after %action action has the correct color placement at corner %corner.', array('%file' => $file, '%action' => $op, '%corner' => $key))); + // We also skip the color test for transparency for gif <-> png + // conversion. The convert operation cannot handle that correctly. + if ($image->getToolkit()->getType() == $image_original_type || $corner != $this->transparent) { + $correct_colors = $this->colorsAreEqual($color, $corner); + $this->assertTrue($correct_colors, String::format('Image %file object after %action action has the correct color placement at corner %corner.', + array('%file' => $file, '%action' => $op, '%corner' => $key))); + } } } diff --git a/core/tests/Drupal/Tests/Core/Image/ImageTest.php b/core/tests/Drupal/Tests/Core/Image/ImageTest.php index 5c67875..e81bb76 100644 --- a/core/tests/Drupal/Tests/Core/Image/ImageTest.php +++ b/core/tests/Drupal/Tests/Core/Image/ImageTest.php @@ -392,7 +392,6 @@ public function testCrop() { * Tests \Drupal\Core\Image\Image::convert(). */ public function testConvert() { - // Test png. $this->getTestImageForOperation('Convert'); $this->toolkitOperation->expects($this->once()) ->method('execute') @@ -400,24 +399,6 @@ public function testConvert() { $ret = $this->image->convert('png'); $this->assertEquals('png', $ret['extension']); - - // Test jpg. - $this->getTestImageForOperation('Convert'); - $this->toolkitOperation->expects($this->once()) - ->method('execute') - ->will($this->returnArgument(0)); - - $ret = $this->image->convert('jpeg'); - $this->assertEquals('jpg', $ret['extension']); - - // Test gif. - $this->getTestImageForOperation('Convert'); - $this->toolkitOperation->expects($this->once()) - ->method('execute') - ->will($this->returnArgument(0)); - - $ret = $this->image->convert('gif'); - $this->assertEquals('gif', $ret['extension']); } /**