home *** CD-ROM | disk | FTP | other *** search
/ CLIX - Fazer Clix Custa Nix / CLIX-CD.cdr / mac / lib / GD.pod < prev    next >
Text File  |  1998-03-12  |  26KB  |  913 lines

  1. =head1 NAME
  2.  
  3. GD.pm - Interface to Gd Graphics Library
  4.  
  5. =head1 DESCRIPTION
  6.  
  7. =head2 The gd Graphics Library
  8.  
  9. The gd graphics library, written by Thomas Boutell of Cold Spring
  10. Harbor Labs (Boutell@netcom.com), is a package of C routines for
  11. creating, reading, writing, and manipulating GIF graphics files.  It
  12. provides graphics primitives for:
  13.  
  14. =over 5
  15.  
  16. =item *
  17. Reading and writing GIF files.
  18.  
  19. =item *
  20. Drawing lines, rectangles, arcs, ellipses and text.
  21.  
  22. =item *
  23. Flood fills.
  24.  
  25. =item *
  26. Using arbitrary images as tiled patterns for filling shapes.
  27.  
  28. =item *
  29. Using arbitrary images as paintbrushes.
  30.  
  31. =item *
  32. Stamping a portion of one image onto another, optionally resizing
  33. it.
  34.  
  35. =item *
  36. Simple text rendering.
  37.  
  38. =back
  39.  
  40. gd can be obtained at URL http://siva.cshl.org/gd/gd.html.  Directions
  41. for installing it, and full documentation are available from that
  42. site.
  43.  
  44. =head2 The GD.pm interface
  45.  
  46. B<GD.pm> is a port of the gd library by Lincoln Stein
  47. (lstein@genome.wi.mit.edu).  It is similar to the original C library,
  48. but contains some modifications to take advantage of perl's
  49. object-oriented features.  It defines the following three classes:
  50.  
  51. =over 5
  52.  
  53. =item C<GD::Image>
  54.  
  55. An image class, which holds the image data and accepts graphic
  56. primitive method calls.
  57.  
  58. =item C<GD::Font>
  59.  
  60. A font class, which holds static font information and used for text
  61. rendering.
  62.  
  63. =item C<GD::Polygon>
  64.  
  65. A simple polygon object, used for storing lists of vertices prior to
  66. rendering a polygon into an image.
  67.  
  68. =back
  69.  
  70. A Simple Example:
  71.  
  72.     #!/usr/local/bin/perl
  73.  
  74.     use GD;
  75.     
  76.     # create a new image
  77.     $im = new GD::Image(100,100);
  78.  
  79.     # allocate some colors
  80.     $white = $im->colorAllocate(255,255,255);
  81.     $black = $im->colorAllocate(0,0,0);       
  82.     $red = $im->colorAllocate(255,0,0);      
  83.     $blue = $im->colorAllocate(0,0,255);
  84.  
  85.     # make the background transparent and interlaced
  86.     $im->transparent($white);
  87.     $im->interlaced('true');
  88.  
  89.     # Put a black frame around the picture
  90.     $im->rectangle(0,0,99,99,$black);
  91.  
  92.     # Draw a blue oval
  93.     $im->arc(50,50,95,75,0,360,$blue);
  94.  
  95.     # And fill it with red
  96.     $im->fill(50,50,$red);
  97.  
  98.     # Convert the image to GIF and print it on standard output
  99.     print $im->gif;
  100.  
  101. Notes:
  102.  
  103. =over 5
  104.  
  105. =item 1.
  106. To create a new, empty image, send a new() message to GD::Image, passing
  107. it the width and height of the image you want to create.  An image
  108. object will be returned.  Other class methods allow you to initialize
  109. an image from a preexisting GIF, GD or XBM file.
  110.  
  111. =item 2.
  112. Next you will ordinarily add colors to the image's color table.
  113. colors are added using a colorAllocate() method call.  The three
  114. parameters in each call are the red, green and blue (rgb) triples for
  115. the desired color.  The method returns the index of that color in the
  116. image's color table.  You should store these indexes for later use.
  117.  
  118. =item 3.
  119. Now you can do some drawing!  The various graphics primitives are
  120. described below.  In this example, we do some text drawing, create an
  121. oval, and create and draw a polygon.
  122.  
  123. =item 4.
  124. Polygons are created with a new() message to GD::Polygon.  You can add
  125. points to the returned polygon one at a time using the addPt() method.
  126. The polygon can then be passed to an image for rendering.
  127.  
  128. =item 5.
  129. When you're done drawing, you can convert the image into GIF format by
  130. sending it a gif() message.  It will return a (potentially large)
  131. scalar value containing the binary data for the image.  Ordinarily you
  132. will print it out at this point or write it to a file.
  133.  
  134. =back
  135.  
  136. =head1 Method Calls
  137.  
  138.  
  139. =head2 Creating and Saving Images
  140.  
  141. =over 5
  142.  
  143. =item C<new>
  144.  
  145. C<GD::Image::new(width,height)> I<class method>
  146.  
  147. To create a new, blank image, send a new() message to the GD::Image
  148. class.  For example:
  149.  
  150.     $myImage = new GD::Image(100,100) || die;
  151.  
  152. This will create an image that is 100 x 100 pixels wide.  If you don't
  153. specify the dimensions, a default of 64 x 64 will be chosen. If
  154. something goes wrong (e.g. insufficient memory), this call will
  155. return undef.
  156.  
  157. =item C<newFromGif>
  158.  
  159. C<GD::Image::newFromGif(FILEHANDLE)> I<class method>
  160.  
  161. This will create an image from a GIF file read in through the provided
  162. filehandle.  The filehandle must previously have been opened on a
  163. valid GIF file or pipe.  If successful, this call will return an
  164. initialized image which you can then manipulate as you please.  If it
  165. fails, which usually happens if the thing at the other end of the
  166. filehandle is not a valid GIF file, the call returns undef.  Notice
  167. that the call doesn't automatically close the filehandle for you.
  168.  
  169. To get information about the size and color usage of the information,
  170. you can call the image query methods described below.
  171.  
  172.     Example usage:
  173.  
  174.     open (GIF,"barnswallow.gif") || die;
  175.     $myImage = newFromGif GD::Image(GIF) || die;
  176.     close GIF;
  177.  
  178. =item C<newFromXbm>
  179.  
  180. C<GD::Image::newFromXbm(FILEHANDLE)> I<class method>
  181.  
  182. This works in exactly the same way as C<newFromGif>, but reads the
  183. contents of an X Bitmap file:
  184.  
  185.     open (XBM,"coredump.xbm") || die;
  186.     $myImage = newFromXbm GD::Image(XBM) || die;
  187.     close XBM;
  188.  
  189. =item C<newFromGd>
  190.  
  191. C<GD::Image::newFromGd(FILEHANDLE)> I<class method>
  192.  
  193. This works in exactly the same way as C<newFromGif>, but reads the
  194. contents of a GD file.  GD is Tom Boutell's disk-based storage format,
  195. intended for the rare case when you need to read and write the image
  196. to disk quickly.  It's not intended for regular use, because, unlike
  197. GIF or JPEG, no image compression is performed and these files can
  198. become B<BIG>.
  199.  
  200.     open (GDF,"godzilla.gd") || die;
  201.     $myImage = newFromGd GD::Image(GDF) || die;
  202.     close GDF;
  203.  
  204. =item C<gif>
  205.  
  206. C<GD::Image::gif> I<object method>
  207.  
  208. This returns the image data in GIF format.  You can then print it,
  209. pipe it to a display program, or write it to a file.  Example:
  210.  
  211.     $gif_data = $myImage->gif;
  212.     open (DISPLAY,"| display -") || die;
  213.     print DISPLAY $gif_data;
  214.     close DISPLAY;
  215.  
  216. =item C<gd>
  217.  
  218. C<GD::Image::gd> I<object method>
  219.  
  220. This returns the image data in GD format.  You can then print it,
  221. pipe it to a display program, or write it to a file.  Example:
  222.  
  223.     print MYOUTFILE $myImage->gd;
  224.  
  225. =back
  226.  
  227. =head2 Color Control
  228.  
  229. =over 5
  230.  
  231. =item C<colorAllocate>
  232.  
  233. C<GD::Image::colorAllocate(red,green,blue)> I<object method>
  234.  
  235. This allocates a color with the specified red, green and blue
  236. components and returns its index in the color table, if specified.
  237. The first color allocated in this way becomes the image's background
  238. color.  (255,255,255) is white (all pixels on).  (0,0,0) is black (all
  239. pixels off).  (255,0,0) is fully saturated red.  (127,127,127) is 50%
  240. gray.  You can find plenty of examples in /usr/X11/lib/X11/rgb.txt.
  241.  
  242. If no colors are allocated, then this function returns -1.
  243.  
  244. Example:
  245.  
  246.     $white = $myImage->colorAllocate(0,0,0); #background color
  247.     $black = $myImage->colorAllocate(255,255,255);
  248.     $peachpuff = $myImage->colorAllocate(255,218,185);
  249.  
  250. =item C<colorDeallocate>
  251.  
  252. C<GD::Image::colorDeallocate(colorIndex)> I<object method> 
  253.  
  254. This marks the color at the specified index as being ripe for
  255. reallocation.  The next time colorAllocate is used, this entry will be
  256. replaced.  You can call this method several times to deallocate
  257. multiple colors.  There's no function result from this call.
  258.  
  259. Example:
  260.  
  261.     $myImage->colorDeallocate($peachpuff);
  262.     $peachy = $myImage->colorAllocate(255,210,185);
  263.  
  264. =item C<colorClosest>
  265.  
  266. C<GD::Image::colorClosest(red,green,blue)> I<object method>
  267.  
  268. This returns the index of the color closest in the color table to the
  269. red green and blue components specified.  If no colors have yet been
  270. allocated, then this call returns -1.
  271.  
  272. Example:
  273.  
  274.     $apricot = $myImage->colorClosest(255,200,180);
  275.  
  276. =item C<colorExact>
  277.  
  278. C<GD::Image::colorExact(red,green,blue)> I<object method>
  279.  
  280. This returns the index of a color that exactly matches the specified
  281. red green and blue components.  If such a color is not in the color
  282. table, this call returns -1.
  283.  
  284.     $rosey = $myImage->colorExact(255,100,80);
  285.     warn "Everything's coming up roses.\n" if $rosey >= 0;
  286.  
  287. =item C<colorsTotal>
  288.  
  289. C<GD::Image::colorsTotal)> I<object method>
  290.  
  291. This returns the total number of colors allocated in the object.
  292.  
  293.     $maxColors = $myImage->colorsTotal;
  294.  
  295. =item C<getPixel>
  296.  
  297. C<GD::Image::getPixel(x,y)> I<object method>
  298.  
  299. This returns the color table index underneath the specified
  300. point.  It can be combined with rgb()
  301. to obtain the rgb color underneath the pixel.
  302.  
  303. Example:
  304.  
  305.         $index = $myImage->getPixel(20,100);
  306.         ($r,$g,$b) = $myImage->rgb($index);
  307.  
  308. =item C<rgb>
  309.  
  310. C<GD::Image::rgb(colorIndex)> I<object method>
  311.  
  312. This returns a list containing the red, green and blue components of
  313. the specified color index.
  314.  
  315. Example:
  316.  
  317.     @RGB = $myImage->rgb($peachy);
  318.  
  319. =item C<transparent>
  320.  
  321. C<GD::Image::transparent(colorIndex)> I<object method>
  322.  
  323. This marks the color at the specified index as being transparent.
  324. Portions of the image drawn in this color will be invisible.  This is
  325. useful for creating paintbrushes of odd shapes, as well as for
  326. making GIF backgrounds transparent for displaying on the Web.  Only
  327. one color can be transparent at any time. To disable transparency, 
  328. specify -1 for the index.  
  329.  
  330. If you call this method without any parameters, it will return the
  331. current index of the transparent color, or -1 if none.
  332.  
  333. Example:
  334.  
  335.     open(GIF,"test.gif");
  336.     $im = newFromGif GD::Image(GIF);
  337.     $white = $im->colorClosest(255,255,255); # find white
  338.     $im->transparent($white);
  339.     print $im->gif;
  340.  
  341. =back
  342.  
  343. =head2 Special Colors
  344.  
  345. GD implements a number of special colors that can be used to achieve
  346. special effects.  They are constants defined in the GD::
  347. namespace, but automatically exported into your namespace when the GD
  348. module is loaded.
  349.  
  350. =over 5
  351.  
  352. =item C<setBrush>
  353.  
  354. =item C<gdBrushed>
  355.  
  356. C<GD::Image::setBrush( )> and C<GD::gdBrushed>
  357.  
  358. You can draw lines and shapes using a brush pattern.  Brushes are 
  359. just images that you can create and manipulate in the usual way. When
  360. you draw with them, their contents are used for the color and shape of
  361. the lines.
  362.  
  363. To make a brushed line, you must create or load the brush first, then
  364. assign it to the image using C<setBrush>.  You can then draw in that
  365. with that brush using the C<gdBrushed> special color.  It's often 
  366. useful to set the background of the brush to transparent so that 
  367. the non-colored parts don't overwrite other parts of your image.
  368.  
  369. Example:
  370.  
  371.     # Create a brush at an angle
  372.     $diagonal_brush = new GD::Image(5,5);
  373.     $white = $diagonal_brush->allocateColor(255,255,255);
  374.     $black = $diagonal_brush->allocateColor(0,0,0);
  375.     $diagonal_brush->transparent($white);
  376.     $diagonal_brush->line(0,4,4,0,$black); # NE diagonal
  377.  
  378.     # Set the brush
  379.     $myImage->setBrush($diagonal_brush);
  380.     
  381.     # Draw a circle using the brush
  382.     $myImage->arc(50,50,25,25,0,360,gdBrushed);
  383.  
  384. =item C<setStyle>
  385.  
  386. =item C<gdStyled>
  387.  
  388. C<GD::Image::setStyle(@colors)> and C<GD::gdStyled>
  389.  
  390. Styled lines consist of an arbitrary series of repeated colors and are
  391. useful for generating dotted and dashed lines.  To create a styled
  392. line, use C<setStyle> to specify a repeating series of colors.  It
  393. accepts an array consisting of one or more color indexes.  Then
  394. draw using the C<gdStyled> special color.  Another special color,
  395. C<gdTransparent> can be used to introduce holes in the line, as the
  396. example shows.
  397.  
  398. Example:
  399.  
  400.     # Set a style consisting of 4 pixels of yellow,
  401.     # 4 pixels of blue, and a 2 pixel gap
  402.     $myImage->setStyle($yellow,$yellow,$yellow,$yellow,
  403.                $blue,$blue,$blue,$blue,
  404.                gdTransparent,gdTransparent);
  405.     $myImage->arc(50,50,25,25,0,360,gdStyled);
  406.  
  407. To combine the C<gdStyled> and C<gdBrushed> behaviors, you can specify
  408. C<gdStyledBrushed>.  In this case, a pixel from the current brush
  409. pattern is rendered wherever the color specified in setStyle() is
  410. neither gdTransparent nor 0.
  411.  
  412. =item C<gdTiled>
  413.  
  414. Draw filled shapes and flood fills using a pattern.  The pattern is
  415. just another image.  The image will be tiled multiple times in order
  416. to fill the required space, creating wallpaper effects.  You must call
  417. C<setTile> in order to define the particular tile pattern you'll use
  418. for drawing when you specify the gdTiled color.
  419. details.
  420.  
  421. =item C<gdStyled>
  422.  
  423. The gdStyled color is used for creating dashed and dotted lines.  A
  424. styled line can contain any series of colors and is created using the
  425. C<setStyled> command.
  426.  
  427. =back
  428.  
  429. =head2 Drawing Commands
  430.  
  431. =over 5
  432.  
  433. =item C<setPixel>
  434.  
  435. C<GD::Image::setPixel(x,y,color)> I<object method> 
  436.  
  437. This sets the pixel at (x,y) to the specified color index.  No value
  438. is returned from this method.  The coordinate system starts at the
  439. upper left at (0,0) and gets larger as you go down and to the right.
  440. You can use a real color, or one of the special colors gdBrushed, 
  441. gdStyled and gdStyledBrushed can be specified.
  442.  
  443. Example:
  444.  
  445.     # This assumes $peach already allocated
  446.     $myImage->setPixel(50,50,$peach);
  447.  
  448. =item C<line>
  449.  
  450. C<GD::Image::line(x1,y1,x2,y2,color)> I<object method>
  451.  
  452. This draws a line from (x1,y1) to (x2,y2) of the specified color.  You
  453. can use a real color, or one of the special colors gdBrushed, 
  454. gdStyled and gdStyledBrushed.
  455.  
  456. Example:
  457.  
  458.     # Draw a diagonal line using the currently defind
  459.     # paintbrush pattern.
  460.     $myImage->line(0,0,150,150,gdBrushed);
  461.  
  462. =item C<dashedLine>
  463.  
  464. C<GD::Image::dashedLine(x1,y1,x2,y2,color)> I<object method>
  465.  
  466. This draws a dashed line from (x1,y1) to (x2,y2) in the specified
  467. color.  A more powerful way to generate arbitrary dashed and dotted
  468. lines is to use the setStyle() method described below and to draw with
  469. the special color gdStyled.
  470.  
  471. Example:
  472.  
  473.     $myImage->dashedLine(0,0,150,150,$blue);
  474.  
  475. =item C<rectangle>
  476.  
  477. C<GD::Image::rectangle(x1,y1,x2,y2,color)> I<object method>
  478.  
  479. This draws a rectangle with the specified color.  (x1,y1) and (x2,y2)
  480. are the upper left and lower right corners respectively.  Both real 
  481. color indexes and the special colors gdBrushed, gdStyled and 
  482. gdStyledBrushed are accepted.
  483.  
  484. Example:
  485.  
  486.     $myImage->rectangle(10,10,100,100,$rose);
  487.  
  488. =item C<filledRectangle>
  489.  
  490. C<GD::Image::filledRectangle(x1,y1,x2,y2,color)> I<object method>
  491.  
  492. This draws a rectangle filed with the specified color.  You can use a
  493. real color, or the special fill color gdTiled to fill the polygon
  494. with a pattern.
  495.  
  496. Example:
  497.  
  498.     # read in a fill pattern and set it
  499.     open(GIF,"happyface.gif") || die;
  500.     $tile = newFromGif GD::Image(GIF);
  501.     $myImage->setTile($tile); 
  502.  
  503.     # draw the rectangle, filling it with the pattern
  504.     $myImage->filledRectangle(10,10,150,200,gdTiled);
  505.  
  506. =item C<polygon>
  507.  
  508. C<GD::Image::polygon(polygon,color)> I<object method> 
  509.  
  510. This draws a polygon with the specified color.  The polygon must be
  511. created first (see below).  The polygon must have at least three
  512. vertices.  If the last vertex doesn't close the polygon, the method
  513. will close it for you.  Both real color indexes and the special 
  514. colors gdBrushed, gdStyled and gdStyledBrushed can be specified.
  515.  
  516. Example:
  517.  
  518.     $poly = new GD::Polygon;
  519.     $poly->addPt(50,0);
  520.     $poly->addPt(99,99);
  521.     $poly->addPt(0,99);
  522.     $myImage->polygon($poly,$blue);
  523.  
  524. =item C<filledPolygon>
  525.  
  526. C<GD::Image::filledPolygon(poly,color)> I<object method>
  527.  
  528. This draws a polygon filled with the specified color.  You can use a
  529. real color, or the special fill color gdTiled to fill the polygon
  530. with a pattern.
  531.  
  532. Example:
  533.  
  534.     # make a polygon
  535.     $poly = new GD::Polygon;
  536.     $poly->addPt(50,0);
  537.     $poly->addPt(99,99);
  538.     $poly->addPt(0,99);
  539.  
  540.     # draw the polygon, filling it with a color
  541.     $myImage->filledPolygon($poly,$peachpuff);
  542.  
  543. =item C<arc>
  544.  
  545. C<GD::Image::arc(cx,cy,width,height,start,end,color)> I<object method>
  546.  
  547. This draws arcs and ellipses.  (cx,cy) are the center of the arc, and
  548. (width,height) specify the width and height, respectively.  The
  549. portion of the ellipse covered by the arc are controlled by start and
  550. end, both of which are given in degrees from 0 to 360.  Zero is at the
  551. top of the ellipse, and angles increase clockwise.  To specify a
  552. complete ellipse, use 0 and 360 as the starting and ending angles.  To
  553. draw a circle, use the same value for width and height.
  554.  
  555. You can specify a normal color or one of the special colors gdBrushed,
  556. gdStyled, or gdStyledBrushed.
  557.  
  558. Example:
  559.  
  560.     # draw a semicircle centered at 100,100
  561.     $myImage->arc(100,100,50,50,0,180,$blue);
  562.  
  563. =item C<fill>
  564.  
  565. C<GD::Image::fill(x,y,color)> I<object method>
  566.  
  567. This method flood-fills regions with the specified color.  The color
  568. will spread through the image, starting at point (x,y), until it is
  569. stopped by a pixel of a different color from the starting pixel (this
  570. is similar to the "paintbucket" in many popular drawing toys).  You
  571. can specify a normal color, or the special color gdTiled, to flood-fill
  572. with patterns.
  573.  
  574. Example:
  575.  
  576.     # Draw a rectangle, and then make its interior blue
  577.     $myImage->rectangle(10,10,100,100,$black);
  578.     $myImage->fill(50,50,$blue);
  579.  
  580. =item C<GD::Image::fillToBorder(x,y,bordercolor,color)> I<object method>
  581.  
  582. Like C<fill>, this method flood-fills regions with the specified color,
  583. starting at position (x,y).
  584. However, instead of stopping when it hits a pixel of a different color
  585. than the starting pixel, flooding will only stop when it hits the
  586. color specified by bordercolor.  You must specify a normal indexed
  587. color for the bordercolor.  However, you are free to use the gdTiled
  588. color for the fill.
  589.  
  590. Example:
  591.  
  592.     # This has the same effect as the previous example
  593.     $myImage->rectangle(10,10,100,100,$black);
  594.     $myImage->fillToBorder(50,50,$black,$blue);
  595.  
  596. =back
  597.  
  598. =head2 Image Copying Commands
  599.  
  600. Two methods are provided for copying a rectangular region from one
  601. image to another.  One method copies a region without resizing it.
  602. The other allows you to stretch the region during the copy operation.
  603.  
  604. With either of these methods it is important to know that the routines
  605. will attempt to flesh out the destination image's color table to match
  606. the colors that are being copied from the source.  If the
  607. destination's color table is already full, then the routines will
  608. attempt to find the best match, with varying results.
  609.  
  610. =over 5
  611.  
  612. =item C<copy>
  613.  
  614. C<GD::Image::copy(sourceImage,dstX,dstY,srcX,srcY,width,height)> I<object method>
  615.  
  616. This is the simpler of the two copy operations, copying the specified
  617. region from the source image to the destination image (the one
  618. performing the method call).  (srcX,srcY) specify the upper left
  619. corner of a rectangle in the source image, and (width,height) give the
  620. width and height of the region to copy.  (dstX,dstY) control where in
  621. the destination image to stamp the copy.  You can use the same image
  622. for both the source and the destination, but the source and
  623. destination regions must not overlap or strange things will happen.
  624.  
  625. Example:
  626.  
  627.     $myImage = new GD::Image(100,100);
  628.     ... various drawing stuff ...
  629.     $srcImage = new GD::Image(50,50);
  630.     ... more drawing stuff ...
  631.     # copy a 25x25 pixel region from $srcImage to
  632.     # the rectangle starting at (10,10) in $myImage
  633.     $myImage->copy($srcImage,10,10,0,0,25,25);
  634.  
  635. =item C<copyResized>
  636.  
  637. C<GD::Image::copyResized(sourceImage,dstX,dstY,srcX,srcY,destW,destH,srcW,srcH)> I<object method>
  638.  
  639. This method is similar to copy() but allows you to choose different
  640. sizes for the source and destination rectangles.  The source and
  641. destination rectangle's are specified independently by (srcW,srcH) and
  642. (destW,destH) respectively.  copyResized() will stretch or shrink the
  643. image to accomodate the size requirements.
  644.  
  645. Example:
  646.  
  647.     $myImage = new GD::Image(100,100);
  648.     ... various drawing stuff ...
  649.     $srcImage = new GD::Image(50,50);
  650.     ... more drawing stuff ...
  651.     # copy a 25x25 pixel region from $srcImage to
  652.     # a larger rectangle starting at (10,10) in $myImage
  653.     $myImage->copyResized($srcImage,10,10,0,0,50,50,25,25);
  654.  
  655. =back
  656.  
  657. =head2 Character and String Drawing
  658.  
  659. Gd allows you to draw characters and strings, either in normal
  660. horizontal orientation or rotated 90 degrees.  These routines use a
  661. GD::Font object, described in more detail below.  There are four
  662. built-in fonts, available in global variables gdLargeFont,
  663. gdMediumBoldFont, gdSmallFont and gdTinyFont.  Currently there is no
  664. way of dynamically creating your own fonts.
  665.  
  666. =over 5
  667.  
  668. =item C<string>
  669.  
  670. C<GD::Image::string(font,x,y,string,color)> I<Object Method>
  671.  
  672. This method draws a string startin at position (x,y) in the specified
  673. font and color.  Your choices of fonts are gdSmallFont, gdMediumBoldFont,
  674. gdTinyFont and gdLargeFont.
  675.  
  676. Example:
  677.  
  678.     $myImage->string(gdSmallFont,2,10,"Peachy Keen",$peach);
  679.  
  680. =item C<stringUp>
  681.  
  682. C<GD::Image::stringUp(font,x,y,string,color)> I<Object Method>
  683.  
  684. Just like the previous call, but draws the text rotated
  685. counterclockwise 90 degrees.
  686.  
  687. =item C<char>
  688.  
  689. =item C<charUp>
  690.  
  691. C<GD::Image::char(font,x,y,char,color)> I<Object Method>
  692. C<GD::Image::charUp(font,x,y,char,color)> I<Object Method>
  693.  
  694. These methods draw single characters at position (x,y) in the
  695. specified font and color.  They're carry-overs from the C interface,
  696. where there is a distinction between characters and strings.  Perl is
  697. insensible to such subtle distinctions.
  698.  
  699. =back
  700.  
  701. =head2 Miscellaneous Image Methods
  702.  
  703. =over 5
  704.  
  705. =item C<interlaced>
  706.  
  707. C<GD::Image::interlaced( )> C<GD::Image::interlaced(1)> I<Object method>
  708.  
  709. This method sets or queries the image's interlaced setting.  Interlace
  710. produces a cool venetian blinds effect on certain viewers.  Provide a
  711. true parameter to set the interlace attribute.  Provide undef to
  712. disable it.  Call the method without parameters to find out the
  713. current setting.
  714.  
  715. =item c<getBounds>
  716.  
  717. C<GD::Image::getBounds( )> I<Object method>
  718.  
  719. This method will return a two-member list containing the width and
  720. height of the image.  You query but not not change the size of the
  721. image once it's created.
  722.  
  723.  
  724. =back
  725.  
  726. =head2 Polygon Methods
  727.  
  728. A few primitive polygon creation and manipulation methods are
  729. provided.  They aren't part of the Gd library, but I thought they
  730. might be handy to have around (they're borrowed from my qd.pl
  731. Quickdraw library).
  732.  
  733. =over 5
  734.  
  735. =item c<new>
  736.  
  737. C<GD::Polygon::new> I<class method>
  738.  
  739. Create an empty polygon with no vertices.
  740.  
  741.     $poly = new GD::Polygon;
  742.  
  743. =item C<addPt>
  744.  
  745. C<GD::Polygon::addPt(x,y)> I<object method>
  746.  
  747. Add point (x,y) to the polygon.
  748.  
  749.     $poly->addPt(0,0);
  750.     $poly->addPt(0,50);
  751.     $poly->addPt(25,25);
  752.     $myImage->fillPoly($poly,$blue);
  753.  
  754. =item C<getPt>
  755.  
  756. C<GD::Polygon::getPt(index)> I<object method>
  757.  
  758. Retrieve the point at the specified vertex.
  759.  
  760.     ($x,$y) = $poly->getPt(2);
  761.  
  762. =item C<setPt>
  763.  
  764. C<GD::Polygon::setPt(index,x,y)> I<object method>
  765.  
  766. Change the value of an already existing vertex.  It is an error to set
  767. a vertex that isn't already defined.
  768.  
  769.     $poly->setPt(2,100,100);
  770.  
  771. =item C<deletePt>
  772.  
  773. C<GD::Polygon:deletePt(index)> I<object method>
  774.  
  775. Delete the specified vertex, returning its value.
  776.  
  777.     ($x,$y) = $poly->deletePt(1); 
  778.  
  779. =item C<length>
  780.  
  781. C<GD::Polygon::length> I<object method>
  782.  
  783. Return the number of vertices in the polygon.
  784.  
  785.     $points = $poly->length;
  786.  
  787. =item C<vertices>
  788.  
  789. C<GD::Polygon::vertices> I<object method>
  790.  
  791. Return a list of all the verticies in the polygon object.  Each
  792. membver of the list is a reference to an (x,y) array.
  793.  
  794.     @vertices = $poly->vertices;
  795.     foreach $v (@vertices)
  796.        print join(",",@$v),"\n";
  797.     }
  798.  
  799. =item C<bounds>
  800.  
  801. C<GD::Polygon::bounds> I<object method>
  802.  
  803. Return the smallest rectangle that completely encloses the polygon.
  804. The return value is an array containing the (left,top,right,bottom) of
  805. the rectangle.
  806.  
  807.     ($left,$top,$right,$bottom) = $poly->bounds;
  808.  
  809. =item C<offset>
  810.  
  811. C<GD::Polygon::offset(dx,dy)> I<object method>
  812.  
  813. Offset all the vertices of the polygon by the specified horizontal
  814. (dh) and vertical (dy) amounts.  Positive numbers move the polygon
  815. down and to the right.
  816.  
  817.     $poly->offset(10,30);
  818.  
  819. =item C<map>
  820.  
  821. C<GD::Polygon::map(srcL,srcT,srcR,srcB,destL,dstT,dstR,dstB)> I<object method>
  822.  
  823. Map the polygon from a source rectangle to an equivalent position in a
  824. destination rectangle, moving it and resizing it as necessary.  See
  825. polys.pl for an example of how this works.  Both the source and
  826. destination rectangles are given in (left,top,right,bottom)
  827. coordinates.  For convenience, you can use the polygon's own bounding
  828. box as the source rectangle.
  829.  
  830.     # Make the polygon really tall
  831.     $poly->map($poly->bounds,0,0,50,200);
  832.  
  833. =back
  834.  
  835. =head2 Font Utilities
  836.  
  837. Gd's support for fonts is minimal.  Basically you have access to
  838. gdSmallFont and gdLargeFont for drawing, and not much else.  However,
  839. for future compatibility, I've made the fonts into perl objects of
  840. type GD::Font that you can query and, perhaps someday manipulate.
  841.  
  842. =over 5
  843.  
  844. =item C<gdSmallFont>
  845.  
  846. C<GD::Font::gdSmallFont> I<constant>
  847.  
  848. This is the basic small font, "borrowed" from a well known public
  849. domain 6x12 font.
  850.  
  851. =item C<gdLargeFont>
  852.  
  853. C<GD::Font::gdLargeFont> I<constant>
  854.  
  855. This is the basic large font, "borrowed" from a well known public
  856. domain 8x16 font.
  857.  
  858. =item C<gdMediumBoldFont>
  859.  
  860. C<GD::Font::gdMediumBoldFont> I<constant>
  861.  
  862. This is a bold font intermediate in size between the small and large
  863. fonts, borrowed from a public domain 7x13 font;
  864.  
  865. =item C<gdTinyFont>
  866.  
  867. C<GD::Font::gdTinyFont> I<constant>
  868.  
  869. This is a tiny, almost unreadable font, 5x8 pixels wide.
  870.  
  871. =item C<nchars>
  872.  
  873. C<GD::Font::nchars> I<object method>
  874.  
  875. This returns the number of characters in the font.
  876.  
  877.     print "The large font contains ",gdLargeFont->nchars," characters\n";
  878.  
  879. =item C<offset>
  880.  
  881. C<GD::Font::offset>     I<object method>
  882.  
  883. This returns the ASCII value of the first character in the font
  884.  
  885. =item C<width>
  886.  
  887. =item C<height>
  888.  
  889. C<GD::Font::width> C<GD::Font::height>  I<object methods>
  890.  
  891. These return the width and height of the font.
  892.  
  893.     ($w,$h) = (gdLargeFont->width,gdLargeFont->height);
  894.  
  895. =back
  896.  
  897. =head1 Copyright Information
  898.  
  899. The GD.pm interface is copyright 1995, Lincoln D. Stein.  You are free
  900. to use it for any purpose, commercial or noncommercial, provided that
  901. if you redistribute the source code this statement of copyright
  902. remains attached. The gd library is covered separately under a 1994
  903. copyright by Quest Protein Database Center, Cold Spring Harbor Labs.
  904. For usage information see the gd documentation at URL
  905.  
  906.     http://siva.cshl.org/gd/gd.html
  907.  
  908. The latest versions of the perl interface are available at
  909.  
  910.     http://www-genome.wi.mit.edu/ftp/pub/software/WWW/GD.html
  911.     ftp://ftp-genome.wi.mit.edu/pub/software/WWW/GD.pm.tar.Z
  912.  
  913.