diff --git a/core/modules/simpletest/files/image-test-transparent-out-of-range.gif b/core/modules/simpletest/files/image-test-transparent-out-of-range.gif new file mode 100644 index 0000000000000000000000000000000000000000..a54df7a93ce2346e19414536a3a8eb555f64f8d1 --- /dev/null +++ b/core/modules/simpletest/files/image-test-transparent-out-of-range.gif @@ -0,0 +1,2 @@ +GIF89a(!,(|80 lݵҍԇd +gp,E Tl {Q1|ĩ^ޮ`L0er ^`7G{vnoyiV40zk*$ar ; \ No newline at end of file diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php index 6234b6aee49bdb5580a4c87d77b41eeb50d06ab3..98ae86393ea2fb47af698c9cdf20e42f32ee64c4 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php @@ -239,7 +239,8 @@ public function createTmp($type, $width, $height) { // truecolor image or if the transparent color is part of the palette. // Since the index of the transparency color is a property of the // image rather than of the palette, it is possible that an image - // could be created with this index set outside the palette size. + // could be created with this index set outside the palette size (see + // http://stackoverflow.com/a/3898007). $transparent_color = imagecolorsforindex($this->getResource(), $transparent); $transparent = imagecolorallocate($res, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']); diff --git a/core/modules/system/src/Tests/Image/ToolkitGdTest.php b/core/modules/system/src/Tests/Image/ToolkitGdTest.php index f3869be3c46c7f246725ad17d6b8f2816d696c50..9288f5df0d7b261f7622338181f957e0ff3b1285 100644 --- a/core/modules/system/src/Tests/Image/ToolkitGdTest.php +++ b/core/modules/system/src/Tests/Image/ToolkitGdTest.php @@ -306,10 +306,39 @@ function testManipulations() { // Check that saved image reloads without raising PHP errors. $image_reloaded = $this->imageFactory->get($file_path); + $resource = $image_reloaded->getToolkit()->getResource(); } } } + /** + * Tests loading an image whose transparent color index is out of range. + */ + function testTransparentColorOutOfRange() { + // This image was generated by taking an initial image with a palette size + // of 6 colors, and setting the transparent color index to 6 (one higher + // than the largest allowed index), as follows: + // @code + // $image = imagecreatefromgif('core/modules/simpletest/files/image-test.gif'); + // imagecolortransparent($image, 6); + // imagegif($image, 'core/modules/simpletest/files/image-test-transparent-out-of-range.gif'); + // @endcode + // This allows us to test that an image with an out-of-range color index + // can be loaded correctly. + $file = 'image-test-transparent-out-of-range.gif'; + $image = $this->imageFactory->get(drupal_get_path('module', 'simpletest') . '/files/' . $file); + $toolkit = $image->getToolkit(); + + if (!$image->isValid()) { + $this->fail(String::format('Could not load image %file.', array('%file' => $file))); + } + else { + // All images should be converted to truecolor when loaded. + $image_truecolor = imageistruecolor($toolkit->getResource()); + $this->assertTrue($image_truecolor, String::format('Image %file after load is a truecolor image.', array('%file' => $file))); + } + } + /** * Tests calling a missing image operation plugin. */