Edit report at http://bugs.php.net/bug.php?id=43475&edit=1
ID: 43475 User updated by: lbayuk at pobox dot com Reported by: lbayuk at pobox dot com Summary: Thick styled lines have scrambled patterns Status: Assigned Type: Bug Package: GD related Operating System: * PHP Version: 5.2CVS-2008-10-30 Assigned To: pajoye Block user comment: N New Comment: OK, thanks, now I understand what it is doing. It is applying the pixels from the style across the width of the line first, then along the length second. But I don't agree that it is working correctly. I think the width and style should be independent, and I think the current behavior may be unintentional. Because gdImageSetPixel increments the style pointer for every pixel, then the order in which the higher-level drawing routines put down the pixels makes a difference in how the pattern is applied. Surely this cannot be useful. As an example, the problem you found with horizontal and vertical lines. If the width is > 1, these are optimized as filled rectangles. But filled rectangles with IMG_COLOR_STYLED are unpredictable, because the result depends on the remainder when dividing the rectangle width by the style array size. (Try drawing 2 filled rectangles with an IMG_COLOR_STYLED pattern, where 1 rectangle is 1 pixel wider than the other. They will look very different.) I would like to hear what the PHP GD maintainer thinks about this. (FYI, now using PHP-5.3.3 with same results) Previous Comments: ------------------------------------------------------------------------ [2010-08-02 21:55:39] php at imperium dot be Lines *do* have the expected style, *EXCEPT* when they are at a 0 or 180 degree angle (e.g. x1==x2). That is where the 'bug' is at. This is probably because imageline tries to be more efficient than it should be, drawing a fast rectangle instead of a thick line. In any case, the style pattern is applied towards the flow of the line instead of linear. This is the correct approach imho and should not be changed. To achieve the same style pattern with a line twice as thick you should double your imagesetstyle as well. E.G. in your test case, 16+4+8+4 for thickness 1 would become 32+8+16+8 for thickness 2. When you adjust your test case like this, you will see that all works as expected except for horizontal lines. Thus, GD maintainer, please adjust the inner workings of imageline so it won't paint a rectangle instead of a thick line (at least not for thickness>1 or when using styled lines). jacQues ------------------------------------------------------------------------ [2008-10-30 17:03:59] j...@php.net Assigned to the GD maintainer. ------------------------------------------------------------------------ [2008-10-27 01:50:09] lbayuk at pobox dot com I tried php5.2-200810262330 (PHP 5.2.7RC3-dev), using bundled gd. There is no difference. The problem is still there, and the image is the same as in 5.2.6. ------------------------------------------------------------------------ [2008-10-24 16:01:49] j...@php.net Please try using this CVS snapshot: http://snaps.php.net/php5.2-latest.tar.gz For Windows: http://windows.php.net/snapshots/ And use the bundled GD library! ------------------------------------------------------------------------ [2007-12-02 02:10:59] lbayuk at pobox dot com Description: ------------ Styled lines with thickness greater than 1 are not drawn correctly. The style pattern is not visible, and the lines have a 'scrambled' or 'plaid' appearance. Reproduce code: --------------- <?php $img = imagecreate(800,800); $bg = ImageColorAllocate($img, 255, 255, 255); $fg = ImageColorAllocate($img, 0, 0, 0); $style = array(); # Make a pattern of 16 on, 4 off, 8 on, 4 off for ($i = 0; $i < 16; $i++) $style[] = $fg; for ($i = 0; $i < 4; $i++) $style[] = IMG_COLOR_TRANSPARENT; for ($i = 0; $i < 8; $i++) $style[] = $fg; for ($i = 0; $i < 4; $i++) $style[] = IMG_COLOR_TRANSPARENT; ImageSetStyle($img, $style); ImageSetThickness($img, 1); ImagePolygon($img,array(50,250,550,250,550,750),3,IMG_COLOR_STYLED); ImageSetThickness($img, 2); ImagePolygon($img,array(100,200,600,200,600,700),3,IMG_COLOR_STYLED); ImageSetThickness($img, 4); ImagePolygon($img,array(150,150,650,150,650,650),3,IMG_COLOR_STYLED); ImageSetThickness($img, 6); ImagePolygon($img,array(200,100,700,100, 700,600),3,IMG_COLOR_STYLED); ImagePng($img); Expected result: ---------------- The output of the script is a PNG file. The image should contain 4 triangles drawn with a styled line (16 pixels on, 4 off, 8 on, 4 off). >From lower left to upper right, the triangles are drawn with line thickness 1, 2, 4, and 6 respectively. The styled pattern should be visible in all of the triangles. Actual result: -------------- The triangle with thickness 1 is correctly drawn. The other triangles are not correctly drawn with the desired line style, although the diagonal part of the thickness 2 triangle looks correct. The other lines appear to have a 'plaid' pattern. Using a 4x screen magnifier, I can see that the multiple parallel lines which make up the thick lines each have the correct style, but the patterns in these lines are offset relative to each other, so the overall appearance does not reflect the desired style. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=43475&edit=1