Bug #53154 [Ver]: Zero-height rectangle has whiskers
| From: | lbayuk at users dot sourceforge dot net | Date: | Sun, 28 Jun 2015 22:28:23 +0000 |
| Subject: | Bug #53154 [Ver]: Zero-height rectangle has whiskers | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-193974@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=53154&edit=1
ID: 53154
User updated by: lbayuk at users dot sourceforge dot net
Reported by: lbayuk at users dot sourceforge dot net
Summary: Zero-height rectangle has whiskers
Status: Verified
Type: Bug
Package: GD related
Operating System: *
PHP Version: 5.6.10
Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
(Sorry for the 'still there' comment... I needed to change my email on the report, and it
doesn't seem to work unless a new comment is added. (Should I open a bug report on the bug
system?))
By "two assignments", do you mean y1v=y1h+1 and y2v=y2h-1 ? Or in the libgd code in your
second link, the in-line equivalents in the 3rd and 4th calls to gdImageLine() ?
These seem to be there to prevent the corner pixels from being drawn twice. That is, the vertical
line segments that make up the rectangle are 2 pixels shorter than the sides of the rectangle. When
the rectangle height is > 0 this prevents the corner pixels from being drawn twice, once as part
of the horizontal segments and once as part of the vertical segments.
But in the edge case of rectangle height = 0, this code causes the "whiskers" on the left
and right ends.
Why would you want to prevent the corner pixels from being drawn twice? The only reason I can think
of where it matters is when alpha blending is on (as it is by default with truecolor images). In
this case, drawing over the same pixel with the same color more than once will darken it each time.
This will be true when the color is partially transparent (alpha > 0).
The effect is subtle, but can be seen with a screen magnifier.
That's my guess, anyway.
Previous Comments:
------------------------------------------------------------------------
[2015-06-28 20:15:09] cmb@php.net
> Verified still there in PHP-5.6.10
Thanks for the reminder. :)
The issue is caused by two strange assignments[1] in the bundled
libgd. Interestingly this code has changed in libgd already two
years ago[2]. I can't find any regression when removing these two
assignments, but I'm puzzled why they're there in the first place.
[1] <http://lxr.php.net/xref/PHP_TRUNK/ext/gd/libgd/gd.c#2096>
[2] <https://github.com/libgd/libgd/commit/a3016ad01b762aa81534ed99ee2af976d45b800a>
------------------------------------------------------------------------
[2015-06-22 21:36:45] lbayuk at users dot sourceforge dot net
Verified still there in PHP-5.6.10
------------------------------------------------------------------------
[2010-10-25 21:31:01] lbayuk at users dot sourceforge dot net
Description:
------------
Using imagerectangle() to draw a rectangle that happens to have zero height results in a horizontal
line with small 'whiskers' at the ends. The whiskers extend up and down 1 pixel from the
line. This looks weird. This only happens with unit line thickness. It does not happen with zero
width rectangles, nor with imagefilledrectangle().
Note: Using PHP-bundled GD library.
Test script:
---------------
<?php
$img = imagecreate(400, 200);
$white = imagecolorallocate($img, 255, 255, 255);
$black = imagecolorallocate($img, 0, 0, 0);
$red = imagecolorallocate($img, 255, 0, 0);
imagestring($img, 4, 5, 5, "RECTANGLES", $black);
imagestring($img, 4, 150, 5, "Filled", $black);
imagestring($img, 4, 300, 5, "Unfilled", $black);
imagestring($img, 4, 5, 75, "Height=0", $black);
imagestring($img, 4, 5, 145, "Width=0", $black);
imagefilledrectangle($img, 150, 95, 200, 95, $black);
imagerectangle($img, 300, 95, 350, 95, $black);
imagefilledrectangle($img, 175, 125, 175, 175, $black);
imagerectangle($img, 325, 125, 325, 175, $black);
imageellipse($img, 325, 95, 90, 50, $red); // Circle the bad one
imagepng($img);
Expected result:
----------------
In all 4 cases, a single line should be drawn.
Actual result:
--------------
The upper right case (zero height, unfilled rectangle) has whiskers at the ends.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=53154&edit=1