Skip to content

Commit cc84d27

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix GH-17373: imagefttext() ignores clipping rect for palette images
2 parents 9f87a19 + 61dcfc4 commit cc84d27

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

ext/gd/libgd/gdft.c

Lines changed: 2 additions & 2 deletions
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

Lines changed: 26 additions & 0 deletions
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)