Skip to content

Commit ec90367

Browse files
committed
Fix GH-17373: imagefttext() ignores clipping rect for palette images
We apply the same fix that has been applied to external libgd at least as of 2.0.29. To avoid issues regarding minor FreeType rendering differences, the test case does not compare against an image, but rather checks that all pixels outside the clipping rect have the background color. Closes GH-17374.
1 parent 5b72f12 commit ec90367

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ PHP NEWS
88
- GD:
99
. Fixed bug GH-17349 (Tiled truecolor filling looses single color
1010
transparency). (cmb)
11+
. Fixed bug GH-17373 (imagefttext() ignores clipping rect for palette
12+
images). (cmb)
1113

1214
- Intl:
1315
. Fixed bug GH-11874 (intl causing segfault in docker images). (nielsdos)

ext/gd/libgd/gdft.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ static char * gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg,
720720
y = pen_y + row;
721721

722722
/* clip if out of bounds */
723-
if (y >= im->sy || y < 0) {
723+
if (y > im->cy2 || y < im->cy1) {
724724
continue;
725725
}
726726

@@ -743,7 +743,7 @@ static char * gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg,
743743
x = pen_x + col;
744744

745745
/* clip if out of bounds */
746-
if (x >= im->sx || x < 0) {
746+
if (x > im->cx2 || x < im->cx1) {
747747
continue;
748748
}
749749
/* get pixel location in gd buffer */

ext/gd/tests/gh17373.phpt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Bug GH-17373 (imagefttext() ignores clipping rect for palette images)
3+
--EXTENSIONS--
4+
gd
5+
--FILE--
6+
<?php
7+
$im = imagecreate(64, 32);
8+
$bg = imagecolorallocate($im, 0, 0, 0);
9+
$fg = imagecolorallocate($im, 255, 255, 255);
10+
imagefilledrectangle($im, 0, 0, 63, 31, $bg);
11+
imagesetclip($im, 32, 0, 63, 31);
12+
imagefttext($im, 16, 0, 10, 23, $fg, __DIR__ . "/Tuffy.ttf", "hello");
13+
14+
imagesetclip($im, 0, 0, 63, 31);
15+
$count = 0;
16+
for ($j = 0; $j < 31; $j++) {
17+
for ($i = 0; $i < 31; $i++) {
18+
if (imagecolorat($im, $i, $j) !== $bg) {
19+
$count++;
20+
}
21+
}
22+
}
23+
var_dump($count);
24+
?>
25+
--EXPECT--
26+
int(0)

0 commit comments

Comments
 (0)