From a1f0ff2d7e312d5c333c4a161028bebbb31fc0de Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Tue, 9 Sep 2014 16:31:48 +0100 Subject: [PATCH] Issue #375062 followup by David_Rothstein: Fixed [follow-up] imagecolorsforindex() Color index nnn out of range in GDToolkit. --- .../image-test-transparent-out-of-range.gif | 2 ++ .../src/Plugin/ImageToolkit/GDToolkit.php | 3 +- .../system/src/Tests/Image/ToolkitGdTest.php | 29 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 core/modules/simpletest/files/image-test-transparent-out-of-range.gif 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 0000000000..a54df7a93c --- /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 6234b6aee4..98ae86393e 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 f3869be3c4..9288f5df0d 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. */ -- GitLab