--- /dev/null
+--TEST--\r
+Bug #53156 (imagerectangle problem with point ordering)\r
+--SKIPIF--\r
+<?php\r
+if (!extension_loaded('gd')) die('skip gd extension not available');\r
+?>\r
+--FILE--\r
+<?php\r
+function draw_and_check_pixel($x, $y)\r
+{\r
+ global $img, $black, $red;\r
+ \r
+ echo (imagecolorat($img, $x, $y) === $black) ? '+' : '-';\r
+ imagesetpixel($img, $x, $y, $red);\r
+}\r
+\r
+function draw_and_check_rectangle($x1, $y1, $x2, $y2)\r
+{\r
+ global $img, $black;\r
+ \r
+ echo 'Rectangle: ';\r
+ imagerectangle($img, $x1, $y1, $x2, $y2, $black);\r
+ draw_and_check_pixel(($x1 + $x2) / 2, $y1);\r
+ draw_and_check_pixel($x1, ($y1 + $y2) / 2);\r
+ draw_and_check_pixel(($x1 + $x2) / 2, $y2);\r
+ draw_and_check_pixel($x2, ($y1 + $y2) / 2);\r
+ echo PHP_EOL;\r
+}\r
+\r
+$img = imagecreate(110, 210);\r
+$bgnd = imagecolorallocate($img, 255, 255, 255);\r
+$black = imagecolorallocate($img, 0, 0, 0);\r
+$red = imagecolorallocate($img, 255, 0, 0);\r
+\r
+draw_and_check_rectangle(10, 10, 50, 50);\r
+draw_and_check_rectangle(50, 60, 10, 100);\r
+draw_and_check_rectangle(50, 150, 10, 110);\r
+draw_and_check_rectangle(10, 200, 50, 160);\r
+imagesetthickness($img, 4);\r
+draw_and_check_rectangle(60, 10, 100, 50);\r
+draw_and_check_rectangle(100, 60, 60, 100);\r
+draw_and_check_rectangle(100, 150, 60, 110);\r
+draw_and_check_rectangle(60, 200, 100, 160);\r
+\r
+imagepng($img, __DIR__ . '/bug53156.png');\r
+?>\r
+--CLEAN--\r
+<?php\r
+@unlink(__DIR__ . '/bug53156.png');\r
+?>\r
+--EXPECT--\r
+Rectangle: ++++\r
+Rectangle: ++++\r
+Rectangle: ++++\r
+Rectangle: ++++\r
+Rectangle: ++++\r
+Rectangle: ++++\r
+Rectangle: ++++\r
+Rectangle: ++++\r