The GD module is available on every platform on which Perl is available. Several versions of Perl come with GD as a standard part of the Perl distribution, such as the Gurusamy Sarathy Win32 port and the Macintosh port, which has GD precompiled in the MacPerl application. Installation methods vary from platform to platform, but if you’ve ever successfully installed a Perl module on your system, you shouldn’t have a problem installing GD. Refer to the README that comes with the package for platform-specific information.
To download the latest version of GD, check CPAN first via http://www.perl.com. The latest version of GD.pm should also be available at http://stein.cshl.org/WWW/software/GD/GD.html. Thomas Boutell’s original C-language version of the libgd library can be found at http://www.boutell.com/gd/gd.html
The copyright to the GD.pm interface is held by Lincoln D. Stein, and it is distributed under similar terms as Perl itself; it is free for any purpose, provided the statement of copyright remains attached to it. The gd C library on which GD is based is covered by a separate copyright held by the Quest Protein Database Center, Cold Spring Harbor Labs, and Thomas Boutell. See the “copying” file that comes with the standard GD distribution for more specific copyright information.
GD provides all of the objects and methods listed in Table 4.1.
Table 4-1. GD’s Object Definitions and Methods, Arranged by Category of Use
Category |
Method |
---|---|
GD Objects |
GD::Image, GD::Font, GD::Polygon |
GD::Image object creation and saving methods |
new( ), newFromGif( ), newFromXbm( ), newFromGd( ), gif( ), gd( ) |
GD::Image color controlmethods |
colorAllocate( ), colorDeallocate( ), colorClosest( ), colorExact( ), colorsTotal( ), getPixel( ), rgb( ), setBrush( ), setPixel( ), setStyle( ), setTile( ), transparent( ) |
GD::Image drawing methods |
line( ), dashedLine( ), rectangle( ), filledRectangle( ), polygon( ), filledPolygon( ), arc( ), fill( ), fillToBorder( ) |
GD::Image drawing constants |
gdBrushed, gdStyled, gdTiled, gdTransparent |
GD::Image copying commands |
copy( ), copyResized( ) |
GD::Image character and string drawing |
string( ), stringUp( ), char( ), charUp( ) |
GD::Image attribute control |
interlaced( ), getBounds( ) |
GD::Polygon object manipulation methods |
new( ), getPt( ), setPt( ), toPt( ), length( ), vertices( ), bounds( ), offset( ), map( ), scale( ), transform( ) |
GD::Font constants |
gdSmallFont, gdLargeFont, gdMediumBoldFont, gdTinyFont, gdGiantFont |
GD::Font information methods |
width( ), height( ) |
GD was designed specifically to handle files in the GIF format. Additional methods are available to read X Bitmap files and read and write files in its own uncompressed GD file format. All image reading and writing happens through the use of filehandles. This allows for a great deal of flexibility in managing the flow of image data. It is simple to write an image to a file, STDOUT, or to pipe image data between processes.
The following methods are available from the GD::Image class for reading and writing images:
Colors are stored within GIF files as indices to a table of no more than 256 colors. GD provides a number of functions for retrieving information about an image’s color table, and for manipulating entries in the table. In addition there are several “special” color constants imported into your script’s namespace that are used to implement different shaped brushes and line styles. These methods and constants are:
For all of the drawing methods, the coordinate system is defined with (0, 0) as the upper-left corner of the image and the x and y values increasing down and to the right. In general, when a method takes a color index as a parameter, you should pass the index of a color previously allocated with one of the methods described in the Section 4.3.3, or use one of the special color constants.
Two methods are provided for copying rectangular regions between images. When copying between images with different color tables, the table of the destination image is filled with as many unique colors from the source image as can fit, and the rest are intelligently matched to colors already in the destination image if the table becomes full.
The following is an alphabetical list of the drawing and manipulation methods:
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.