From: Operating system: Linux PHP version: 5.3.3 Package: GD related Bug Type: Bug Bug description:imagerectangle problem with point ordering
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 bug report at http://bugs.php.net/bug.php?id=53156&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53156&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53156&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53156&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=53156&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53156&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=53156&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=53156&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=53156&r=needscript Try newer version: http://bugs.php.net/fix.php?id=53156&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=53156&r=support Expected behavior: http://bugs.php.net/fix.php?id=53156&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=53156&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=53156&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=53156&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53156&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=53156&r=dst IIS Stability: http://bugs.php.net/fix.php?id=53156&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=53156&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=53156&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=53156&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=53156&r=mysqlcfg