CGI and Perl

GD::Polygon Module

The GD::Polygon module provides an interface to a polygon shape for use with the GD::Image::polygon() and GD::Image::filledPolygon() methods. Polygons consist of vertices that are defined as Cartesian coordinates. You construct polygon objects by using the new() method and the addPt(x,y) method. addPt(x,y) adds a vertex to the polygon.

A triangle, for example, might have vertices of (0,0), (10,10), and (10,0). getPt(index), setPt(index,x,y), and deletePt(index) getPt() returns the point corresponding to the vertex at a given index. setPt()enables you to modify the vertex at index to contain the new point (x,y). deletePt() deletes a vertex from the polygon. length() and vertices() length()returns the number of vertices in the polygon, and vertices()returns a list of those vertices. The list returned by vertices() contains references to arrays containing the (x,y) coordinates of each vertex.

bounds() The bounds()method returns the smallest bounding rectangle of the polygon specified as the list ($left,$top,$right,$bottom), where each of these variables is a reference to an array specifying the (x,y) coordinate values. offset(dx,dy) The offset(dx,dy) method enables you to move a polygon by a specified offset of dx and dy. Each vertex is offset by these amounts. This method is useful for the animation of a polygon. map(srcL,srcT,srcR,srcB,destL,destT,destR,destB) The map(srcL,srcT,srcR,srcB,destL,destT,destR,destB) method maps a polygon from a source rectangle to an equivalent position within a destination rectangle. The polygon is moved and resized according to the mapping between the two rectangles. You can use the bounding box of the polygon itself as the srcL, srcT, srcR, and srcB values.

GD::Font Module

As I mentioned previously, four fonts are available for use within the GD module. These fonts are specified as constants and are exported into your namespace when you load the GD module. This class additionally provides methods for querying the font. nchars() returns the number of glyphs contained in the font, offset() returns the ASCII value of the first character in the font, and width() and height() return the width and height of the font.

Currently, you cannot create your own fonts or manipulate the predefined fonts. Perhaps this support will be added to the GD library one day.

You can find the latest GD module in your nearest CPAN location, along with a more complete reference of the functionality. For more information on the GD library, refer to