Skip to content

Commit 9a5669b

Browse files
committed
Merge branch 'PHP-7.3'
* PHP-7.3: Fix #77200: imagecropauto(…, GD_CROP_SIDES) crops left but not right
2 parents 65b34bf + 070f683 commit 9a5669b

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

ext/gd/libgd/gd_crop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ static int gdGuessBackgroundColorFromCorners(gdImagePtr im, int *color)
279279
} else if (tl == tr || tl == bl || tl == br) {
280280
*color = tl;
281281
return 2;
282-
} else if (tr == bl) {
282+
} else if (tr == bl || tr == br) {
283283
*color = tr;
284284
return 2;
285285
} 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)