]> granicus.if.org Git - php/commitdiff
Fix #50194: imagettftext broken on transparent background w/o alphablending
authorChristoph M. Becker <cmbecker69@gmx.de>
Wed, 14 Sep 2016 12:59:17 +0000 (14:59 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Wed, 14 Sep 2016 13:47:32 +0000 (15:47 +0200)
We must not draw the background pixels of the character glyphs, what has
already been fixed in GD 2.0.26.

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

diff --git a/NEWS b/NEWS
index b7f466dc2ebd201f4bc7901645ff1da796eb29b2..61f96093d681e0edf0f353bfc164b7f6f42de943 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,8 @@ PHP                                                                        NEWS
 - GD:
   . Fixed bug #67325 (imagetruecolortopalette: white is duplicated in palette).
     (cmb)
+  . Fixed bug #50194 (imagettftext broken on transparent background w/o
+    alphablending). (cmb)
 
 - Mbstring:
   . Fixed bug #72994 (mbc_to_code() out of bounds read). (Laruence, cmb)
index ba905dc0a86386ef885eb223d7c950a89c744fcc..be9ae6177b559a75b4351122026c3393712552b1 100644 (file)
@@ -659,6 +659,8 @@ static char * gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg,
                                } else {
                                        return "Unsupported ft_pixel_mode";
                                }
+                               if (level == 0)  /* if background */
+                                       continue;
                                if ((fg >= 0) && (im->trueColor)) {
                                        /* Consider alpha in the foreground color itself to be an
                                         * upper bound on how opaque things get, when truecolor is
diff --git a/ext/gd/tests/bug50194.phpt b/ext/gd/tests/bug50194.phpt
new file mode 100644 (file)
index 0000000..91b7b35
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+Bug #50194 (imagettftext broken on transparent background w/o alphablending)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+if (!function_exists('imagettftext')) die('skip imagettftext() not available');
+?>
+--FILE--
+<?php
+require_once __DIR__ . DIRECTORY_SEPARATOR . 'func.inc';
+
+$im = imagecreatetruecolor(240, 55);
+$background = imagecolorallocatealpha($im, 60, 60, 60, 0); // no tranparency
+$black = imagecolorallocate($im, 0, 0, 0);
+imagealphablending($im, false); 
+imagefilledrectangle($im, 0, 0, 239, 54, $background);
+$text = 'Testing ... ';
+$font = __DIR__ . DIRECTORY_SEPARATOR . 'Tuffy.ttf';
+imagettftext($im, 40, 0, 10, 40, $black, $font, $text);
+imagesavealpha($im, true);
+
+test_image_equals_file(__DIR__ . DIRECTORY_SEPARATOR . 'bug50194.png', $im);
+
+imagedestroy($im);
+?>
+===DONE===
+--EXPECT--
+The images are equal.
+===DONE===
diff --git a/ext/gd/tests/bug50194.png b/ext/gd/tests/bug50194.png
new file mode 100644 (file)
index 0000000..5bbf5ba
Binary files /dev/null and b/ext/gd/tests/bug50194.png differ