summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmb@php.net>2015-07-21 01:13:04 +0200
committerChristoph M. Becker <cmb@php.net>2015-07-21 01:13:04 +0200
commitf1228ebc61eb79e9435f462fc925605973d3415a (patch)
tree83cf565003b226468c21e2f33ac20ef6ffdee2ba
parent8461a874543fed9219aa2aaddd1974b5da394235 (diff)
parent2ec86112932e57b3f28a6448b5175a4089810cea (diff)
downloadphp-git-f1228ebc61eb79e9435f462fc925605973d3415a.tar.gz
Merge branch 'pull-request/1425' into PHP-5.6
* pull-request/1425: revised bug53156.phpt Fix #53156: imagerectangle problem with point ordering
-rw-r--r--ext/gd/libgd/gd.c4
-rw-r--r--ext/gd/tests/bug53156.phpt57
2 files changed, 60 insertions, 1 deletions
diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c
index 529ba56f1a..6005a69cf4 100644
--- a/ext/gd/libgd/gd.c
+++ b/ext/gd/libgd/gd.c
@@ -2048,7 +2048,9 @@ void gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
t=y1;
y1 = y2;
y2 = t;
-
+ }
+
+ if (x2 < x1) {
t = x1;
x1 = x2;
x2 = t;
diff --git a/ext/gd/tests/bug53156.phpt b/ext/gd/tests/bug53156.phpt
new file mode 100644
index 0000000000..24db8024fe
--- /dev/null
+++ b/ext/gd/tests/bug53156.phpt
@@ -0,0 +1,57 @@
+--TEST--
+Bug #53156 (imagerectangle problem with point ordering)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+?>
+--FILE--
+<?php
+function draw_and_check_pixel($x, $y)
+{
+ global $img, $black, $red;
+
+ echo (imagecolorat($img, $x, $y) === $black) ? '+' : '-';
+ imagesetpixel($img, $x, $y, $red);
+}
+
+function draw_and_check_rectangle($x1, $y1, $x2, $y2)
+{
+ global $img, $black;
+
+ echo 'Rectangle: ';
+ imagerectangle($img, $x1, $y1, $x2, $y2, $black);
+ $x = ($x1 + $x2) / 2;
+ $y = ($y1 + $y2) / 2;
+ draw_and_check_pixel($x, $y1);
+ draw_and_check_pixel($x1, $y);
+ draw_and_check_pixel($x, $y2);
+ draw_and_check_pixel($x2, $y);
+ echo PHP_EOL;
+}
+
+$img = imagecreate(110, 210);
+$bgnd = imagecolorallocate($img, 255, 255, 255);
+$black = imagecolorallocate($img, 0, 0, 0);
+$red = imagecolorallocate($img, 255, 0, 0);
+
+draw_and_check_rectangle( 10, 10, 50, 50);
+draw_and_check_rectangle( 50, 60, 10, 100);
+draw_and_check_rectangle( 50, 150, 10, 110);
+draw_and_check_rectangle( 10, 200, 50, 160);
+imagesetthickness($img, 4);
+draw_and_check_rectangle( 60, 10, 100, 50);
+draw_and_check_rectangle(100, 60, 60, 100);
+draw_and_check_rectangle(100, 150, 60, 110);
+draw_and_check_rectangle( 60, 200, 100, 160);
+
+//imagepng($img, __DIR__ . '/bug53156.png'); // debug
+?>
+--EXPECT--
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++