Name
setBrush( ) — assign a brush to an image
Synopsis
GD::Image::setBrush(image
)
The drawing
commands available through GD can be called with either a solid color
or with a special
brush that is accessed
via the gdBrushed constant. This brush is simply
another image that must be created or read in from another GIF file.
The setBrush
( ) method assigns a particular
image as the current brush for drawing within another image. To draw
with a brush follow these five steps:
Create a new image object for the brush, or read the brush from a GIF file. Here we will create a new square 20 × 20 pixel brush:
my $brush = new GD::Image(20, 20);
If you are creating a new brush with the GD drawing commands, allocate a color for the brush and draw the brush shape. In this case, the brush is a red circle:
my $red = $brush->allocateColor(255, 0, 0); $brush->arc(10, 10, 20, 20, 0, 360, $red);
If you are creating an irregularly shaped brush, set the background color of the brush with the
transparent( )
method so that the brush does not overwrite its own path:my $white = $brush->allocateColor(255, 255, 255); $brush->transparent($white);
Assign the brush to the image you want to draw on:
$image->setBrush($brush);
Call a drawing command with gdBrushed as the
color
parameter to use the brush:$image->line(0, 0, 50, 50, gdBrushed);
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.