Name
setStyle( ) — assign a line style to an image
Synopsis
GD::Image::setStyle(@colorindices
)
Dotted and dashed
lines can be
drawn using the GD drawing commands with the gdStyled
line style instead of the colorindex
parameter. The setStyle( )
method
defines a line style for an image. Follow these steps to create a
styled line:
Allocate the colors you wish to use in the line style, or get their color indices with the
colorExact( )
method:$blue = $image->colorAllocate(0, 0, 255); # allocate blue $red = $image->colorAllocate(255, 0, 0); # allocate red
Create a list of color indices. Each element of the list represents one pixel in a sequence that will be repeated over the length of the drawn line. To indicate a blank space in a dashed line, use the gdTransparent constant instead of a color index. If a color index has already been marked as transparent for the image, it will also be transparent in the drawn line. To indicate a blue and red dashed line that repeats blue for two pixels, red for three pixels, and then a two-pixel break, use the following for the color list:
@linestyle = ($blue, $blue, $red, $red, $red, gdTransparent, gdTransparent);
Assign the style to the image:
$image->setStyle(@linestyle);
Draw with a drawing method and the gdStyled special color. If the gdStyledBrushed constant is used, the brush pattern will be drawn for those pixels that are not set to gdTransparent. To draw a dashed rectangle, use:
$image->rectangle(0, 0, 100, 100, gdStyled);
Use setStyle( )
when you need ...
Get Programming Web Graphics with Perl and GNU Softwar now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.