Name

polygon( ) — draw a previously created polygon shape

Synopsis

GD::Image::polygon(polygon, colorindex)
                     

This is a drawing method that will allow you to draw a polygon defined by a GD::Polygon object onto an image. You must first create a polygon object and define its points with the addPt( ) method; a polygon must have at least three points, the first and last of which will be automatically connected when it is drawn to the image. To create a four-sided red parallelogram, for example, use:

my $red = $image->colorAllocate(255, 0, 0);  # Allocate a color index for red
my $parallelogram = new GD::Polygon;         # Create the polygon object
$parallelogram->addPt(20, 20);               # Add the four vertices
$parallelogram->addPt(0, 100);
$parallelogram->addPt(100, 100);
$parallelogram->addPt(120, 20);             
$image->polygon($parallelogram, $red);      # Draw the polygon on the image

To draw a filled polygon, use this method followed by a call to fill( ), or use the filledPolygon( ) method. The colorindexparameter specifies the color or style of the line of the polygon, and can be one of the following:

A color index

The lines of the polygon will be drawn in the specified color. If the color has been marked as transparent, the pixels will become transparent.

gdBrushed

The lines of the polygon will be drawn using the current brush shape, set with setBrush( ). To create rectangles with sides thicker than one pixel, use a brush of the desired thickness.

gdStyled

The lines of the polygon will be drawn with dashes defined by ...

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.