diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2018-11-25 19:00:50 +0100 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2018-11-25 19:00:50 +0100 |
commit | a1aaec08b5a3fc0f36cf91f034b4232285c6e793 (patch) | |
tree | c8de58d8f7251015a4c88eecd244f052105a836e | |
parent | b47b8886dd17d080c74c401f7893ba9f4ccb83d3 (diff) | |
download | php-git-a1aaec08b5a3fc0f36cf91f034b4232285c6e793.tar.gz |
Fix #77200: imagecropauto(…, GD_CROP_SIDES) crops left but not right
We apply the upstream patch[1].
[1] <https://github.com/libgd/libgd/commit/6613094e5d218dc4d4372757aef5e58c6462a9f7>
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | ext/gd/libgd/gd_crop.c | 2 | ||||
-rw-r--r-- | ext/gd/tests/bug77200.phpt | 37 |
3 files changed, 40 insertions, 1 deletions
@@ -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). diff --git a/ext/gd/libgd/gd_crop.c b/ext/gd/libgd/gd_crop.c index 0b918c74c8..33c3723080 100644 --- a/ext/gd/libgd/gd_crop.c +++ b/ext/gd/libgd/gd_crop.c @@ -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) { diff --git a/ext/gd/tests/bug77200.phpt b/ext/gd/tests/bug77200.phpt new file mode 100644 index 0000000000..704b1796e7 --- /dev/null +++ b/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=== |