Skip to content

Commit

Permalink
Fix #77200: imagecropauto(…, GD_CROP_SIDES) crops left but not right
Browse files Browse the repository at this point in the history
We apply the upstream patch[1].

[1] <libgd/libgd@6613094>
  • Loading branch information
cmb69 committed Nov 25, 2018
1 parent b47b888 commit a1aaec0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS
Expand Up @@ -12,6 +12,8 @@ PHP NEWS
- GD:
. Fixed bug #77195 (Incorrect error handling of imagecreatefromjpeg()). (cmb)
. Fixed bug #77198 (auto cropping has insufficient precision). (cmb)
. Fixed bug #77200 (imagecropauto(…, GD_CROP_SIDES) crops left but not right).
(cmb)

- Sockets:
. Fixed bug #77136 (Unsupported IPV6_RECVPKTINFO constants on macOS).
Expand Down
2 changes: 1 addition & 1 deletion ext/gd/libgd/gd_crop.c
Expand Up @@ -315,7 +315,7 @@ static int gdGuessBackgroundColorFromCorners(gdImagePtr im, int *color)
} else if (tl == tr || tl == bl || tl == br) {
*color = tl;
return 2;
} else if (tr == bl) {
} else if (tr == bl || tr == br) {
*color = tr;
return 2;
} else if (br == bl) {
Expand Down
37 changes: 37 additions & 0 deletions ext/gd/tests/bug77200.phpt
@@ -0,0 +1,37 @@
--TEST--
Bug #77200 (imagecropauto(…, GD_CROP_SIDES) crops left but not right)
--SKIPIF--
<?php
if (!extension_loaded('gd')) die('skip gd extension not available');
if (!GD_BUNDLED) die('upstream bugfix has not been released');
?>
--FILE--
<?php

$orig = imagecreatetruecolor(8, 8);
$red = imagecolorallocate($orig, 255, 0, 0);
$green = imagecolorallocate($orig, 0, 255, 0);
$blue = imagecolorallocate($orig, 0, 0, 255);

imagefilledrectangle($orig, 0, 0, 3, 3, $green); // tl
imagefilledrectangle($orig, 4, 0, 7, 3, $red); // tr
imagefilledrectangle($orig, 0, 4, 3, 7, $green); // bl
imagefilledrectangle($orig, 4, 4, 7, 7, $blue); // br

$cropped = imagecropauto($orig, IMG_CROP_SIDES);
var_dump(imagesx($cropped));

imagefilledrectangle($orig, 0, 0, 3, 3, $red); // tl
imagefilledrectangle($orig, 4, 0, 7, 3, $green); // tr
imagefilledrectangle($orig, 0, 4, 3, 7, $blue); // bl
imagefilledrectangle($orig, 4, 4, 7, 7, $green); // br

$cropped = imagecropauto($orig, IMG_CROP_SIDES);
var_dump(imagesx($cropped));

?>
===DONE===
--EXPECT--
int(4)
int(4)
===DONE===

0 comments on commit a1aaec0

Please sign in to comment.