summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2015-07-20 02:11:18 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2015-07-20 02:14:29 +0200
commit72b73e24a00b9872214fbcc256ee38431d9c9d47 (patch)
treeed105de6546469633b633429fdf915b0809d837f
parent90de2aeaac3de8f0744853ba197457c2241a4bdf (diff)
downloadphp-git-72b73e24a00b9872214fbcc256ee38431d9c9d47.tar.gz
Fix #53156: imagerectangle problem with point ordering
Contrary to imagefilledrectangle(), imagerectangle() has the documented limitation that the given points have to be the upper left and the lower right corner, respectively. However, libgd already caters to upper right / lower left pairs, and not catering to the other two combinations seems to be an oversight.
-rw-r--r--ext/gd/libgd/gd.c4
-rw-r--r--ext/gd/tests/bug53156.phpt59
2 files changed, 62 insertions, 1 deletions
diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c
index c75c985c4e..f03fd0278a 100644
--- a/ext/gd/libgd/gd.c
+++ b/ext/gd/libgd/gd.c
@@ -2044,7 +2044,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..a269369670
--- /dev/null
+++ b/ext/gd/tests/bug53156.phpt
@@ -0,0 +1,59 @@
+--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);
+ draw_and_check_pixel(($x1 + $x2) / 2, $y1);
+ draw_and_check_pixel($x1, ($y1 + $y2) / 2);
+ draw_and_check_pixel(($x1 + $x2) / 2, $y2);
+ draw_and_check_pixel($x2, ($y1 + $y2) / 2);
+ 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');
+?>
+--CLEAN--
+<?php
+@unlink(__DIR__ . '/bug53156.png');
+?>
+--EXPECT--
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++
+Rectangle: ++++