]> granicus.if.org Git - php/commitdiff
Fix #72913: imagecopy() loses single-color transparency on palette images
authorChristoph M. Becker <cmbecker69@gmx.de>
Sun, 21 Aug 2016 15:39:23 +0000 (17:39 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Sun, 21 Aug 2016 15:39:23 +0000 (17:39 +0200)
The proper code to handle true-color to palette copies is already contained
in gdImageCopy(), so we can simply remove the buggy duplicated code.

NEWS
ext/gd/libgd/gd.c
ext/gd/tests/bug72913.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 676760ef6ffe80949c0dcb54541def176ef8f9ea..fb5a07cfbed29c09b60d42b5590d478f568f20fb 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,8 @@ PHP                                                                        NEWS
 - GD:
   . Fixed bug #66005 (imagecopy does not support 1bit transparency on truecolor
     images). (cmb)
+  . Fixed bug #72913 (imagecopy() loses single-color transparency on palette
+    images). (cmb)
 
 - JSON:
   . Fixed bug #72787 (json_decode reads out of bounds). (Jakub Zelenka)
index 364697338e95ceb978196db24e721ce477f9d384..0b4b42fa27558fa32cc54e14dc297d9d0ba10832 100644 (file)
@@ -2266,26 +2266,6 @@ void gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX,
                return;
        }
 
-       /* Destination is palette based */
-       if (src->trueColor) { /* But source is truecolor (Ouch!) */
-               toy = dstY;
-               for (y = srcY; (y < (srcY + h)); y++) {
-                       tox = dstX;
-                       for (x = srcX; x < (srcX + w); x++) {
-                               int nc;
-                               c = gdImageGetPixel (src, x, y);
-
-                               /* Get best match possible. */
-                               nc = gdImageColorResolveAlpha(dst, gdTrueColorGetRed(c), gdTrueColorGetGreen(c), gdTrueColorGetBlue(c), gdTrueColorGetAlpha(c));
-
-                               gdImageSetPixel(dst, tox, toy, nc);
-                               tox++;
-                       }
-                       toy++;
-               }
-               return;
-       }
-
        /* Palette based to palette based */
        for (i = 0; i < gdMaxColors; i++) {
                colorMap[i] = (-1);
diff --git a/ext/gd/tests/bug72913.phpt b/ext/gd/tests/bug72913.phpt
new file mode 100644 (file)
index 0000000..0ad03a7
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+Bug #72913 (imagecopy() loses single-color transparency on palette images)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+?>
+--FILE--
+<?php
+$base64 = 'iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAIAAACRXR/mAAAABnRSTlMAAAAAAABu'
+    . 'pgeRAAAAVklEQVRYw+3UQQqAMBAEwf3/p9eTBxEPiWAmWMU8oGFJqgAAuOpzWTX3'
+    . 'xQUti+uRJTZ9V5aY1bOTFZLV7yZr9zt6ibv/qPXfrMpsGipbIy7oqQ8AYJED1plD'
+    . 'y5PCu2sAAAAASUVORK5CYII=';
+$src = imagecreatefromstring(base64_decode($base64));
+
+$dst = imagecreate(50, 50);
+$transparent = imagecolorallocatealpha($dst, 255, 255, 255, 127);
+imagealphablending($dst, false);
+imagesavealpha($dst, true);
+
+imagecopy($dst, $src, 0,0, 0,0, 50,50);
+
+ob_start();
+imagegd($dst);
+echo md5(ob_get_clean()), PHP_EOL;
+?>
+==DONE==
+--EXPECT--
+f03c27f20710e21debd7090c660f1a1e
+==DONE==