Edit report at https://bugs.php.net/bug.php?id=53156&edit=1
ID: 53156
Updated by: cmb@php.net
Reported by: lbayuk at users dot sourceforge dot net
Summary: imagerectangle problem with point ordering
-Status: Verified
+Status: Closed
Type: Bug
Package: GD related
Operating System: Linux
PHP Version: 5.6.11
Assigned To: pajoye
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=72b73e24a00b9872214fbcc256ee38431d9c9d47
Log: Fix #53156: imagerectangle problem with point ordering
Previous Comments:
------------------------------------------------------------------------
[2015-07-20 00:38:46] cmb@php.net
I can confirm the behavior.
IMHO this is more of a bug than a documentation issue. Therefore
I've submitted a PR with lbayuk's patch.
------------------------------------------------------------------------
[2015-06-22 21:41:37] lbayuk at users dot sourceforge dot net
Verified still there in PHP-5.6.10
------------------------------------------------------------------------
[2013-06-25 16:28:48] felipe@php.net
What do you think about, Pierre?
------------------------------------------------------------------------
[2010-10-25 21:50:51] lbayuk at users dot sourceforge dot net
Description:
------------
The documentation says imagerectangle() requires the upper left point first, then the lower right,
whereas imagefilledrectangle() accepts the points in any order. In fact, imagerectangle() does work
with all 4 possible orderings of the points, but only when drawing with unit thickness. When
drawing rectangles with thickness > 1, only 2 of the 4 cases work.
Before marking this as "working as documented" (which it is), please consider that there
seems to be incorrect logic in gdImageRectangle() when handling the points. It tests for y2<y1
and if so it swaps both X and Y. It should test and swap X and Y independently, same as
gdImageFilledRectangle does. So it seems to already be trying to avoid this requirement for point
order, but it doesn't quite work in all cases.
Test script:
---------------
<?php
$img = imagecreate(400, 800);
$bgnd = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);
$green = imagecolorallocate($img, 0, 255, 0);
imagesetthickness($img, 4);
imagestring($img, 4, 20, 140, 'Order: upper left, lower right', $black);
imagerectangle($img, 20, 20, 120, 120, $black);
imagefilledrectangle($img, 15, 15, 25, 25, $green); // Mark start point
imagestring($img, 4, 20, 340, 'Order: lower left, upper right', $black);
imagerectangle($img, 20, 320, 120, 220, $black);
imagefilledrectangle($img, 15, 315, 25, 325, $green); // Mark start point
imagestring($img, 4, 20, 540, 'Order: Upper right, lower left', $black);
imagerectangle($img, 120, 420, 20, 520, $black);
imagefilledrectangle($img, 115, 415, 125, 425, $green); // Mark start point
imagestring($img, 4, 20, 740, 'Order: Lower right, upper left', $black);
imagerectangle($img, 120, 720, 20, 620, $black);
imagefilledrectangle($img, 115, 715, 125, 725, $green); // Mark start point
imagepng($img);
Expected result:
----------------
4 rectangles, drawn with thick lines.
Actual result:
--------------
2 rectangles, and two sets of parallel lines.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=53156&edit=1