Page 1 of 1

Stroke not always rendered for tiled paths

Posted: 2006-12-02T13:39:31-07:00
by loris
I was originally hesitant to post this, but I'm now sure I've found a bug.

I'm using perlmagick (ImageMagick 6.3.0) and generating vertical graduated fills for draw paths:
1) create 1-pixel wide graduated image, height of object
2) composite this onto a 1-pixel wide image the height of the destination image, at the appropriate y-offset.
3) draw the object using the tile option.

The problem I found was that my mask didn't cover the entire height of the object. After some investigation, I discovered that if there is a thick stroke line specified then it isn't rendered as line, but as fill (tile). So there is a region at the top and bottom of the drawn area which is outside the graduated region created in (2).
I tried to make a small demo of this, and the damn thing renders fine.
In fact this problem seems to be quite dependent on the parameters used:

Code: Select all

$image->Draw(primitive=>'path',points=>$points,
stroke=>$current[$pp{linecol}],
strokewidth=>2,
$drawstyle=>$drawfn,
antialias=>'true');
renders fine (embedded in my program), while

Code: Select all

$image->Draw(primitive=>'path',points=>$points,
stroke=>$current[$pp{linecol}],
strokewidth=>3,
$drawstyle=>$drawfn,
antialias=>'true');
doesn't. The stroke isn't drawn.

The pragmatic solution is to do the fill separately, but still, it rankles. And the current behaviour is clearly buggy.

Posted: 2006-12-02T14:32:41-07:00
by magick
Post a short program with the fewest lines possible that illustrate the problem. We need to reproduce the problem before we can investigate further.

Posted: 2006-12-04T06:14:55-07:00
by loris
magick wrote: Post a short program with the fewest lines possible that illustrate the problem. We need to reproduce the problem before we can investigate further.


I tried to make a demo before and it didn't didn't work. :?
BUT after some more experimentation, I found that if I simplified the path, it did. This may be useful diagnostic information in itself- if you add a move and second sub-element, it does draw the stroke.

Here is the demo:

Code: Select all

#!/usr/bin/perl -w
#demo of thick line with tiled object bug - line drawn as fill

use Image::Magick;
$image=Image::Magick->new;
$width=100;$height=100;
$image->Set(size=>"${width}x$height");
$image->ReadImage('xc:white');
$image->Set('pixel[49,49]'=>'red');#standard demo canvas

#set up the gradient to be used for the tiled pattern, and top and bottom of demo rectangles
$min=30;$max=70;
$gradheight=$max-$min+1;
$pattern=Image::Magick->new;
$pattern->Set(size=>"1x$gradheight");
$pattern->ReadImage('gradient:#0F0-blue');
$ygradient=Image::Magick->new;
$ygradient->Set(size=>"1x$height");
$ygradient->ReadImage('xc:black');
$ygradient->Composite(image=>$pattern,geometry=>"1x$max",#compose=>'src',
                    gravity=>'NorthWest',y=>$min);

#draw the gradient so it can be visualised
$image->Draw(primitive=>'path',points=>'M10 0L20 0 20 100 10 100 10 0',
             stroke=>'none',tile=>$ygradient);

###############################################################################
#this routine demonstrates the bug. parameters are - left and right sides, and line width
draw_rectangle(60,70,2);#draws fine, with stroke
draw_rectangle(80,90,3);#stroke not drawn!

$image->Set(compression=>'LZW');

$filename = "image.gif";
open(IMAGE, ">$filename");
$image->Write(file=>\*IMAGE, filename=>$filename);
close(IMAGE);
undef $image;

exit(0);
sub draw_rectangle{
($left,$right,$linewidth)=@_;
$points="M$left ${min}L$right $min $right $max $left $max $left $min z";
        $image->Draw(primitive=>'path',points=>$points,
            stroke=>'red',
            strokewidth=>$linewidth,
            'tile'=>$ygradient,
            antialias=>'true');
};
I hope this is helpful.

Posted: 2006-12-04T08:22:26-07:00
by magick
We'll investigate and get back to you.