Skip to content

Commit a1aaec0

Browse files
committed
Fix #77200: imagecropauto(…, GD_CROP_SIDES) crops left but not right
We apply the upstream patch[1]. [1] <libgd/libgd@6613094>
1 parent b47b888 commit a1aaec0

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ PHP NEWS
1212
- GD:
1313
. Fixed bug #77195 (Incorrect error handling of imagecreatefromjpeg()). (cmb)
1414
. Fixed bug #77198 (auto cropping has insufficient precision). (cmb)
15+
. Fixed bug #77200 (imagecropauto(…, GD_CROP_SIDES) crops left but not right).
16+
(cmb)
1517

1618
- Sockets:
1719
. Fixed bug #77136 (Unsupported IPV6_RECVPKTINFO constants on macOS).

ext/gd/libgd/gd_crop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ static int gdGuessBackgroundColorFromCorners(gdImagePtr im, int *color)
315315
} else if (tl == tr || tl == bl || tl == br) {
316316
*color = tl;
317317
return 2;
318-
} else if (tr == bl) {
318+
} else if (tr == bl || tr == br) {
319319
*color = tr;
320320
return 2;
321321
} else if (br == bl) {

ext/gd/tests/bug77200.phpt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Bug #77200 (imagecropauto(…, GD_CROP_SIDES) crops left but not right)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
if (!GD_BUNDLED) die('upstream bugfix has not been released');
7+
?>
8+
--FILE--
9+
<?php
10+
11+
$orig = imagecreatetruecolor(8, 8);
12+
$red = imagecolorallocate($orig, 255, 0, 0);
13+
$green = imagecolorallocate($orig, 0, 255, 0);
14+
$blue = imagecolorallocate($orig, 0, 0, 255);
15+
16+
imagefilledrectangle($orig, 0, 0, 3, 3, $green); // tl
17+
imagefilledrectangle($orig, 4, 0, 7, 3, $red); // tr
18+
imagefilledrectangle($orig, 0, 4, 3, 7, $green); // bl
19+
imagefilledrectangle($orig, 4, 4, 7, 7, $blue); // br
20+
21+
$cropped = imagecropauto($orig, IMG_CROP_SIDES);
22+
var_dump(imagesx($cropped));
23+
24+
imagefilledrectangle($orig, 0, 0, 3, 3, $red); // tl
25+
imagefilledrectangle($orig, 4, 0, 7, 3, $green); // tr
26+
imagefilledrectangle($orig, 0, 4, 3, 7, $blue); // bl
27+
imagefilledrectangle($orig, 4, 4, 7, 7, $green); // br
28+
29+
$cropped = imagecropauto($orig, IMG_CROP_SIDES);
30+
var_dump(imagesx($cropped));
31+
32+
?>
33+
===DONE===
34+
--EXPECT--
35+
int(4)
36+
int(4)
37+
===DONE===

0 commit comments

Comments
 (0)