Skip to content

Commit 2c658f4

Browse files
committed
Fix GH-17349: Tiled truecolor filling looses single color transparency
This is porting the relevant part of a previous upstream commit[1] to align the behavior of our bundled libgd with upstream. It should be noted that this only works if the image actually has a transparent color. [1] <libgd/libgd@4770e2b> Closes GH-17351.
1 parent a970eef commit 2c658f4

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ PHP NEWS
55
- FTP:
66
. Fixed bug GH-16800 (ftp functions can abort with EINTR). (nielsdos)
77

8+
- GD:
9+
. Fixed bug GH-17349 (Tiled truecolor filling looses single color
10+
transparency). (cmb)
11+
812
- Intl:
913
. Fixed bug GH-11874 (intl causing segfault in docker images). (nielsdos)
1014

ext/gd/libgd/gd.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,9 @@ static int gdImageTileGet (gdImagePtr im, int x, int y)
960960
srcy = y % gdImageSY(im->tile);
961961
p = gdImageGetPixel(im->tile, srcx, srcy);
962962

963-
if (im->trueColor) {
963+
if (p == im->tile->transparent) {
964+
tileColor = im->transparent;
965+
} else if (im->trueColor) {
964966
if (im->tile->trueColor) {
965967
tileColor = p;
966968
} else {

ext/gd/tests/gh17349.phpt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
GH-17349 (Tiled truecolor filling looses single color transparency)
3+
--EXTENSIONS--
4+
gd
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/func.inc";
8+
9+
$tile = imagecreatetruecolor(8, 8);
10+
$red = imagecolorallocate($tile, 255, 0, 0);
11+
imagefilledrectangle($tile, 0, 0, 7, 7, $red);
12+
imagecolortransparent($tile, $red);
13+
14+
$im = imagecreatetruecolor(64, 64);
15+
$bg = imagecolorallocate($im, 255, 255, 255);
16+
imagefilledrectangle($im, 0, 0, 63, 63, $bg);
17+
imagecolortransparent($im, $bg);
18+
$fg = imagecolorallocate($im, 0, 0, 0);
19+
imageellipse($im, 31, 31, 50, 50, $fg);
20+
imagesettile($im, $tile);
21+
imagealphablending($im, false);
22+
imagefill($im, 31, 31, IMG_COLOR_TILED);
23+
24+
test_image_equals_file(__DIR__ . "/gh17349.png", $im);
25+
?>
26+
--EXPECT--
27+
The images are equal.

ext/gd/tests/gh17349.png

417 Bytes
Loading

0 commit comments

Comments
 (0)