Skip to content

Commit 09eb6ed

Browse files
committed
Fix #50194: imagettftext broken on transparent background w/o alphablending
We must not draw the background pixels of the character glyphs, what has already been fixed in GD 2.0.26.
1 parent 05baa92 commit 09eb6ed

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ PHP NEWS
1818
- GD:
1919
. Fixed bug #67325 (imagetruecolortopalette: white is duplicated in palette).
2020
(cmb)
21+
. Fixed bug #50194 (imagettftext broken on transparent background w/o
22+
alphablending). (cmb)
2123

2224
- Mbstring:
2325
. Fixed bug #72994 (mbc_to_code() out of bounds read). (Laruence, cmb)

ext/gd/libgd/gdft.c

+2
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,8 @@ static char * gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg,
659659
} else {
660660
return "Unsupported ft_pixel_mode";
661661
}
662+
if (level == 0) /* if background */
663+
continue;
662664
if ((fg >= 0) && (im->trueColor)) {
663665
/* Consider alpha in the foreground color itself to be an
664666
* upper bound on how opaque things get, when truecolor is

ext/gd/tests/bug50194.phpt

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Bug #50194 (imagettftext broken on transparent background w/o alphablending)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
if (!function_exists('imagettftext')) die('skip imagettftext() not available');
7+
?>
8+
--FILE--
9+
<?php
10+
require_once __DIR__ . DIRECTORY_SEPARATOR . 'func.inc';
11+
12+
$im = imagecreatetruecolor(240, 55);
13+
$background = imagecolorallocatealpha($im, 60, 60, 60, 0); // no tranparency
14+
$black = imagecolorallocate($im, 0, 0, 0);
15+
imagealphablending($im, false);
16+
imagefilledrectangle($im, 0, 0, 239, 54, $background);
17+
$text = 'Testing ... ';
18+
$font = __DIR__ . DIRECTORY_SEPARATOR . 'Tuffy.ttf';
19+
imagettftext($im, 40, 0, 10, 40, $black, $font, $text);
20+
imagesavealpha($im, true);
21+
22+
test_image_equals_file(__DIR__ . DIRECTORY_SEPARATOR . 'bug50194.png', $im);
23+
24+
imagedestroy($im);
25+
?>
26+
===DONE===
27+
--EXPECT--
28+
The images are equal.
29+
===DONE===

ext/gd/tests/bug50194.png

2.76 KB
Loading

0 commit comments

Comments
 (0)