Skip to content

Commit 16d6a93

Browse files
committed
Merge branch 'PHP-5.6'
* PHP-5.6: updated NEWS revised bug53156.phpt Fix #53156: imagerectangle problem with point ordering
2 parents b8534da + e3a8507 commit 16d6a93

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

ext/gd/libgd/gd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2046,7 +2046,9 @@ void gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
20462046
t=y1;
20472047
y1 = y2;
20482048
y2 = t;
2049-
2049+
}
2050+
2051+
if (x2 < x1) {
20502052
t = x1;
20512053
x1 = x2;
20522054
x2 = t;

ext/gd/tests/bug53156.phpt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
--TEST--
2+
Bug #53156 (imagerectangle problem with point ordering)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
function draw_and_check_pixel($x, $y)
10+
{
11+
global $img, $black, $red;
12+
13+
echo (imagecolorat($img, $x, $y) === $black) ? '+' : '-';
14+
imagesetpixel($img, $x, $y, $red);
15+
}
16+
17+
function draw_and_check_rectangle($x1, $y1, $x2, $y2)
18+
{
19+
global $img, $black;
20+
21+
echo 'Rectangle: ';
22+
imagerectangle($img, $x1, $y1, $x2, $y2, $black);
23+
$x = ($x1 + $x2) / 2;
24+
$y = ($y1 + $y2) / 2;
25+
draw_and_check_pixel($x, $y1);
26+
draw_and_check_pixel($x1, $y);
27+
draw_and_check_pixel($x, $y2);
28+
draw_and_check_pixel($x2, $y);
29+
echo PHP_EOL;
30+
}
31+
32+
$img = imagecreate(110, 210);
33+
$bgnd = imagecolorallocate($img, 255, 255, 255);
34+
$black = imagecolorallocate($img, 0, 0, 0);
35+
$red = imagecolorallocate($img, 255, 0, 0);
36+
37+
draw_and_check_rectangle( 10, 10, 50, 50);
38+
draw_and_check_rectangle( 50, 60, 10, 100);
39+
draw_and_check_rectangle( 50, 150, 10, 110);
40+
draw_and_check_rectangle( 10, 200, 50, 160);
41+
imagesetthickness($img, 4);
42+
draw_and_check_rectangle( 60, 10, 100, 50);
43+
draw_and_check_rectangle(100, 60, 60, 100);
44+
draw_and_check_rectangle(100, 150, 60, 110);
45+
draw_and_check_rectangle( 60, 200, 100, 160);
46+
47+
//imagepng($img, __DIR__ . '/bug53156.png'); // debug
48+
?>
49+
--EXPECT--
50+
Rectangle: ++++
51+
Rectangle: ++++
52+
Rectangle: ++++
53+
Rectangle: ++++
54+
Rectangle: ++++
55+
Rectangle: ++++
56+
Rectangle: ++++
57+
Rectangle: ++++

0 commit comments

Comments
 (0)