home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / GD.pm < prev    next >
Encoding:
Perl POD Document  |  2004-02-06  |  57.9 KB  |  1,847 lines

  1. package GD;
  2.  
  3. # Copyright 1995 Lincoln D. Stein.  See accompanying README file for
  4. # usage information
  5.  
  6. require 5.004;
  7. require FileHandle;
  8. require Exporter;
  9. require DynaLoader;
  10. require AutoLoader;
  11. use Symbol 'gensym','qualify_to_ref';
  12. use Carp 'croak','carp';
  13. use strict;
  14. use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $AUTOLOAD);
  15. $VERSION = "2.12";
  16.  
  17. @ISA = qw(Exporter DynaLoader);
  18. # Items to export into callers namespace by default. Note: do not export
  19. # names by default without a very good reason. Use EXPORT_OK instead.
  20. # Do not simply export all your public functions/methods/constants.
  21. @EXPORT = qw(
  22.     gdBrushed
  23.     gdDashSize
  24.     gdMaxColors
  25.     gdStyled
  26.     gdStyledBrushed
  27.     gdTiled
  28.     gdTransparent
  29.     gdAntiAliased
  30.         gdArc
  31.         gdChord
  32.         gdPie
  33.         gdNoFill
  34.         gdEdged
  35.     gdTinyFont
  36.     gdSmallFont
  37.     gdMediumBoldFont
  38.     gdLargeFont
  39.     gdGiantFont
  40.     gdAlphaMax
  41.     gdAlphaOpaque
  42.     gdAlphaTransparent
  43. );
  44.  
  45. @EXPORT_OK = qw (
  46.     GD_CMP_IMAGE 
  47.         GD_CMP_NUM_COLORS
  48.     GD_CMP_COLOR
  49.     GD_CMP_SIZE_X
  50.     GD_CMP_SIZE_Y
  51.         GD_CMP_TRANSPARENT
  52.     GD_CMP_BACKGROUND
  53.     GD_CMP_INTERLACE
  54.     GD_CMP_TRUECOLOR
  55. );
  56.  
  57. %EXPORT_TAGS = ('cmp'  => [qw(GD_CMP_IMAGE 
  58.                   GD_CMP_NUM_COLORS
  59.                   GD_CMP_COLOR
  60.                   GD_CMP_SIZE_X
  61.                   GD_CMP_SIZE_Y
  62.                   GD_CMP_TRANSPARENT
  63.                   GD_CMP_BACKGROUND
  64.                   GD_CMP_INTERLACE
  65.                   GD_CMP_TRUECOLOR
  66.                  )
  67.               ]
  68.            );
  69.  
  70. # documentation error
  71. *GD::Polygon::delete = \&GD::Polygon::deletePt;
  72. *GD::Image::stringTTF = \&GD::Image::stringFT;
  73.  
  74. sub AUTOLOAD {
  75.     # This AUTOLOAD is used to 'autoload' constants from the constant()
  76.     # XS function.  If a constant is not found then control is passed
  77.     # to the AUTOLOAD in AutoLoader.
  78.  
  79.     my($constname);
  80.     ($constname = $AUTOLOAD) =~ s/.*:://;
  81.     my $val = constant($constname, @_ ? $_[0] : 0);
  82.     if ($! != 0) {
  83.     if ($! =~ /Invalid/) {
  84.         $AutoLoader::AUTOLOAD = $AUTOLOAD;
  85.         goto &AutoLoader::AUTOLOAD;
  86.     }
  87.     else {
  88.         my($pack,$file,$line) = caller;
  89.         die "Your vendor has not defined GD macro $pack\:\:$constname, used at $file line $line.\n";
  90.     }
  91.     }
  92.     eval "sub $AUTOLOAD { $val }";
  93.     goto &$AUTOLOAD;
  94. }
  95.  
  96. bootstrap GD;
  97.  
  98. # Preloaded methods go here.
  99. sub GD::gdSmallFont {
  100.     return &GD::Font::Small;
  101. }
  102.  
  103. sub GD::gdLargeFont {
  104.     return &GD::Font::Large;
  105. }
  106.  
  107. sub GD::gdMediumBoldFont {
  108.     return &GD::Font::MediumBold;
  109. }
  110.  
  111. sub GD::gdTinyFont {
  112.     return &GD::Font::Tiny;
  113. }
  114.  
  115. sub GD::gdGiantFont {
  116.     return &GD::Font::Giant;
  117. }
  118.  
  119.  
  120. sub GD::Image::_make_filehandle {
  121.   shift;  # get rid of class
  122.   no strict 'refs';
  123.   my $thing = shift;
  124.   return $thing if defined(fileno $thing);
  125.  
  126.   # otherwise try qualifying it into caller's package
  127.   my $fh;
  128.   {   
  129.     local $^W = 0;  # to avoid uninitialized variable warning from Symbol.pm
  130.     $fh = qualify_to_ref($thing,caller(2));
  131.   }
  132.   return $fh if defined(fileno $fh);
  133.  
  134.   # otherwise treat it as a file to open
  135.   $fh = gensym;
  136.   open($fh,$thing) || return;
  137.   return $fh;
  138. }
  139.  
  140. sub GD::Image::new {
  141.   my $pack = shift;
  142.   if (@_ == 1) {
  143.     if (my $type = _image_type($_[0])) {
  144.       my $method = "newFrom${type}Data";
  145.       return unless $pack->can($method);
  146.       return $pack->$method($_[0]);
  147.     }
  148.     return unless my $fh = $pack->_make_filehandle($_[0]);
  149.     my $magic;
  150.     return unless read($fh,$magic,4);
  151.     return unless my $type = _image_type($magic);
  152.     seek($fh,0,0);
  153.     my $method = "newFrom${type}";
  154.     return $pack->$method($fh);
  155.   }
  156.   return $pack->_new(@_);
  157. }
  158.  
  159. sub GD::Image::newTrueColor {
  160.   my $pack = shift;
  161.   return $pack->_new(@_, 1);
  162. }
  163.  
  164. sub GD::Image::newPalette {
  165.   my $pack = shift;
  166.   return $pack->_new(@_, 0);
  167. }
  168.  
  169. sub GD::Image::newFromPng {
  170.     croak("Usage: newFromPng(class,filehandle,[truecolor])") unless @_>=2;
  171.     my($class) = shift;
  172.     my($f)     = shift;
  173.     my $fh = $class->_make_filehandle($f);
  174.     binmode($fh);
  175.     $class->_newFromPng($fh,@_);
  176. }
  177.  
  178. sub GD::Image::newFromJpeg {
  179.     croak("Usage: newFromJpeg(class,filehandle,[truecolor])") unless @_>=2;
  180.     my($class) = shift;
  181.     my($f)     = shift;
  182.     my $fh = $class->_make_filehandle($f);
  183.     binmode($fh);
  184.     $class->_newFromJpeg($fh,@_);
  185. }
  186.  
  187. sub GD::Image::newFromXbm {
  188.     croak("Usage: newFromXbm(class,filehandle)") unless @_==2;
  189.     my($class,$f) = @_;
  190.     my $fh = $class->_make_filehandle($f);
  191.     binmode($fh);
  192.     $class->_newFromXbm($fh);
  193. }
  194.  
  195. sub GD::Image::newFromGd {
  196.     croak("Usage: newFromGd(class,filehandle)") unless @_==2;
  197.     my($class,$f) = @_;
  198.     my $fh = $class->_make_filehandle($f);
  199.     binmode($fh);
  200.     $class->_newFromGd($fh);
  201. }
  202.  
  203. sub GD::Image::newFromGd2 {
  204.     croak("Usage: newFromGd2(class,filehandle)") unless @_==2;
  205.     my($class,$f) = @_;
  206.     my $fh = $class->_make_filehandle($f);
  207.     binmode($fh);
  208.     $class->_newFromGd2($fh);
  209. }
  210.  
  211. sub GD::Image::newFromGd2Part {
  212.     croak("Usage: newFromGd2(class,filehandle,srcX,srcY,width,height)") unless @_==6;
  213.     my($class,$f) = splice(@_,0,2);
  214.     my $fh = $class->_make_filehandle($f);
  215.     binmode($fh);
  216.     $class->_newFromGd2Part($fh,@_);
  217. }
  218.  
  219. sub GD::Image::ellipse ($$$$$) {
  220.   my ($self,$cx,$cy,$width,$height,$color) = @_;
  221.   $self->arc($cx,$cy,$width,$height,0,360,$color);
  222. }
  223.  
  224. sub _image_type {
  225.   my $data = shift;
  226.   my $magic = substr($data,0,4);
  227.   return 'Png'  if $magic eq "\x89PNG";
  228.   return 'Jpeg' if $magic eq "\377\330\377\340";
  229.   return 'Jpeg' if $magic eq "\377\330\377\341";
  230.   return 'Jpeg' if $magic eq "\377\330\377\356";
  231.   return 'Gd2'  if $magic eq "gd2\000";
  232.   return 'Xpm'  if substr($data,0,9) eq "/* XPM */";
  233.   return;
  234. }
  235.  
  236.  
  237. sub GD::Image::clone {
  238.   croak("Usage: clone(\$image)") unless @_ == 1;
  239.   my $self = shift;
  240.   my ($x,$y) = $self->getBounds;
  241.   my $new = $self->new($x,$y);
  242.   return unless $new;
  243.   $new->copy($self,0,0,0,0,$x,$y);
  244.   return $new;
  245. }
  246.  
  247. ### The polygon object ###
  248. # create a new polygon
  249. sub GD::Polygon::new {
  250.     my $class = shift;
  251.     return bless { 'length'=>0,'points'=>[] },$class;
  252. }
  253.  
  254. # automatic destruction of the polygon
  255. sub GD::Polygon::DESTROY {
  256.     my $self = shift;
  257.     undef $self->{'points'};
  258. }
  259.  
  260. # add an x,y vertex to the polygon
  261. sub GD::Polygon::addPt {
  262.     my($self,$x,$y) = @_;
  263.     push(@{$self->{'points'}},[$x,$y]);
  264.     $self->{'length'}++;
  265. }
  266.  
  267. # get a vertex
  268. sub GD::Polygon::getPt {
  269.     my($self,$index) = @_;
  270.     return () unless ($index>=0) && ($index<$self->{'length'});
  271.     return @{$self->{'points'}->[$index]};
  272. }
  273.  
  274. # change the value of a vertex
  275. sub GD::Polygon::setPt {
  276.     my($self,$index,$x,$y) = @_;
  277.     unless (($index>=0) && ($index<$self->{'length'})) {
  278.     carp "Attempt to set an undefined polygon vertex";
  279.     return undef;
  280.     }
  281.     @{$self->{'points'}->[$index]} = ($x,$y);
  282.     1;
  283. }
  284.  
  285. # return the total number of vertices
  286. sub GD::Polygon::length {
  287.     my $self = shift;
  288.     return $self->{'length'};
  289. }
  290.  
  291. # return the array of vertices.
  292. # each vertex is an two-member (x,y) array
  293. sub GD::Polygon::vertices {
  294.     my $self = shift;
  295.     return @{$self->{'points'}};
  296. }
  297.  
  298. # return the bounding box of the polygon
  299. # (smallest rectangle that contains it)
  300. sub GD::Polygon::bounds {
  301.     my $self = shift;
  302.     my($top,$bottom,$left,$right) = @_;
  303.     $top =    99999999;
  304.     $bottom =-99999999;
  305.     $left =   99999999;
  306.     $right = -99999999;
  307.     my $v;
  308.     foreach $v ($self->vertices) {
  309.     $left = $v->[0] if $left > $v->[0];
  310.     $right = $v->[0] if $right < $v->[0];
  311.     $top = $v->[1] if $top > $v->[1];
  312.     $bottom = $v->[1] if $bottom < $v->[1];
  313.     }
  314.     return ($left,$top,$right,$bottom);
  315. }
  316.  
  317. # delete a vertex, returning it, just for fun
  318. sub GD::Polygon::deletePt {
  319.      my($self,$index) = @_;
  320.      unless (($index>=0) && ($index<@{$self->{'points'}})) {
  321.      carp "Attempt to delete an undefined polygon vertex";
  322.      return undef;
  323.      }
  324.       my($vertex) = splice(@{$self->{'points'}},$index,1);
  325.      $self->{'length'}--;
  326.       return @$vertex;
  327.   }
  328.  
  329. # translate the polygon in space by deltaX and deltaY
  330. sub GD::Polygon::offset {
  331.     my($self,$dh,$dv) = @_;
  332.     my $size = $self->length;
  333.     my($i);
  334.     for ($i=0;$i<$size;$i++) {
  335.     my($x,$y)=$self->getPt($i);
  336.     $self->setPt($i,$x+$dh,$y+$dv);
  337.     }
  338. }
  339.  
  340. # map the polygon from sourceRect to destRect,
  341. # translating and resizing it if necessary
  342. sub GD::Polygon::map {
  343.     my($self,$srcL,$srcT,$srcR,$srcB,$destL,$destT,$destR,$destB) = @_;
  344.     my($factorV) = ($destB-$destT)/($srcB-$srcT);
  345.     my($factorH) = ($destR-$destL)/($srcR-$srcL);
  346.     my($vertices) = $self->length;
  347.     my($i);
  348.     for ($i=0;$i<$vertices;$i++) {
  349.     my($x,$y) = $self->getPt($i);
  350.     $x = int($destL + ($x - $srcL) * $factorH);
  351.     $y = int($destT + ($y - $srcT) * $factorV);
  352.     $self->setPt($i,$x,$y);
  353.     }
  354. }
  355.  
  356. # draws closed polygon with the specified color
  357. sub GD::Image::polygon {
  358.     my $self = shift;
  359.     my($p,$c) = @_;
  360.     $self->openPolygon($p, $c);
  361.     $self->line( @{$p->{'points'}->[0]},
  362.         @{$p->{'points'}->[$p->{'length'}-1]}, $c);
  363. }
  364.  
  365. # These routines added by Winfriend Koenig.
  366. sub GD::Polygon::toPt {
  367.     my($self, $dx, $dy) = @_;
  368.     unless ($self->length > 0) {
  369.     $self->addPt($dx,$dy);
  370.     return;
  371.     }
  372.     my ($x, $y) = $self->getPt($self->length-1);
  373.     $self->addPt($x+$dx,$y+$dy);
  374. }
  375.  
  376. sub GD::Polygon::transform($$$$$$$) {
  377.     # see PostScript Ref. page 154
  378.     my($self, $a, $b, $c, $d, $tx, $ty) = @_;
  379.     my $size = $self->length;
  380.     for (my $i=0;$i<$size;$i++) {
  381.     my($x,$y)=$self->getPt($i);
  382.     $self->setPt($i, $a*$x+$c*$y+$tx, $b*$x+$d*$y+$ty);
  383.     }
  384. }
  385.  
  386. sub GD::Polygon::scale {
  387.     my($self, $sx, $sy) = @_;
  388.     $self->transform($sx,0,0,$sy,0,0);
  389. }
  390.  
  391.  
  392. # Autoload methods go after __END__, and are processed by the autosplit program.
  393. 1;
  394. __END__
  395.  
  396. =head1 NAME
  397.  
  398. GD.pm - Interface to Gd Graphics Library
  399.  
  400. =head1 SYNOPSIS
  401.  
  402.     use GD;
  403.  
  404.     # create a new image
  405.     $im = new GD::Image(100,100);
  406.  
  407.     # allocate some colors
  408.     $white = $im->colorAllocate(255,255,255);
  409.     $black = $im->colorAllocate(0,0,0);       
  410.     $red = $im->colorAllocate(255,0,0);      
  411.     $blue = $im->colorAllocate(0,0,255);
  412.  
  413.     # make the background transparent and interlaced
  414.     $im->transparent($white);
  415.     $im->interlaced('true');
  416.  
  417.     # Put a black frame around the picture
  418.     $im->rectangle(0,0,99,99,$black);
  419.  
  420.     # Draw a blue oval
  421.     $im->arc(50,50,95,75,0,360,$blue);
  422.  
  423.     # And fill it with red
  424.     $im->fill(50,50,$red);
  425.  
  426.     # make sure we are writing to a binary stream
  427.     binmode STDOUT;
  428.  
  429.     # Convert the image to PNG and print it on standard output
  430.     print $im->png;
  431.  
  432. =head1 DESCRIPTION
  433.  
  434. B<GD.pm> is a Perl interface to Thomas Boutell's gd graphics library
  435. (version 2.01 or higher; see below). GD allows you to create color
  436. drawings using a large number of graphics primitives, and emit the
  437. drawings as PNG files.
  438.  
  439. GD defines the following three classes:
  440.  
  441. =over 5
  442.  
  443. =item C<GD::Image>
  444.  
  445. An image class, which holds the image data and accepts graphic
  446. primitive method calls.
  447.  
  448. =item C<GD::Font>
  449.  
  450. A font class, which holds static font information and used for text
  451. rendering.
  452.  
  453. =item C<GD::Polygon>
  454.  
  455. A simple polygon object, used for storing lists of vertices prior to
  456. rendering a polygon into an image.
  457.  
  458. =back
  459.  
  460. A Simple Example:
  461.  
  462.     #!/usr/local/bin/perl
  463.  
  464.     use GD;
  465.     
  466.     # create a new image
  467.     $im = new GD::Image(100,100);
  468.  
  469.     # allocate some colors
  470.     $white = $im->colorAllocate(255,255,255);
  471.     $black = $im->colorAllocate(0,0,0);       
  472.     $red = $im->colorAllocate(255,0,0);      
  473.     $blue = $im->colorAllocate(0,0,255);
  474.  
  475.     # make the background transparent and interlaced
  476.     $im->transparent($white);
  477.     $im->interlaced('true');
  478.  
  479.     # Put a black frame around the picture
  480.     $im->rectangle(0,0,99,99,$black);
  481.  
  482.     # Draw a blue oval
  483.     $im->arc(50,50,95,75,0,360,$blue);
  484.  
  485.     # And fill it with red
  486.     $im->fill(50,50,$red);
  487.  
  488.     # make sure we are writing to a binary stream
  489.     binmode STDOUT;
  490.  
  491.     # Convert the image to PNG and print it on standard output
  492.     print $im->png;
  493.  
  494. Notes:
  495.  
  496. =over 5
  497.  
  498. =item 1.
  499. To create a new, empty image, send a new() message to GD::Image, passing
  500. it the width and height of the image you want to create.  An image
  501. object will be returned.  Other class methods allow you to initialize
  502. an image from a preexisting JPG, PNG, GD, GD2 or XBM file.
  503.  
  504. =item 2.
  505. Next you will ordinarily add colors to the image's color table.
  506. colors are added using a colorAllocate() method call.  The three
  507. parameters in each call are the red, green and blue (rgb) triples for
  508. the desired color.  The method returns the index of that color in the
  509. image's color table.  You should store these indexes for later use.
  510.  
  511. =item 3.
  512. Now you can do some drawing!  The various graphics primitives are
  513. described below.  In this example, we do some text drawing, create an
  514. oval, and create and draw a polygon.
  515.  
  516. =item 4.
  517. Polygons are created with a new() message to GD::Polygon.  You can add
  518. points to the returned polygon one at a time using the addPt() method.
  519. The polygon can then be passed to an image for rendering.
  520.  
  521. =item 5.
  522. When you're done drawing, you can convert the image into PNG format by
  523. sending it a png() message.  It will return a (potentially large)
  524. scalar value containing the binary data for the image.  Ordinarily you
  525. will print it out at this point or write it to a file.  To ensure
  526. portability to platforms that differentiate between text and binary
  527. files, be sure to call C<binmode()> on the file you are writing
  528. the image to.
  529.  
  530. =back
  531.  
  532. =head1 Object Constructors: Creating Images
  533.  
  534. The following class methods allow you to create new GD::Image objects.
  535.  
  536. =over 4
  537.  
  538. =item B<$image = GD::Image-E<gt>new([$width,$height],[$truecolor])>
  539.  
  540. =item B<$image = GD::Image-E<gt>new(*FILEHANDLE)>
  541.  
  542. =item B<$image = GD::Image-E<gt>new($filename)>
  543.  
  544. =item B<$image = GD::Image-E<gt>new($data)>
  545.  
  546. The new() method is the main constructor for the GD::Image class.
  547. Called with two integer arguments, it creates a new blank image of the
  548. specified width and height. For example:
  549.  
  550.     $myImage = new GD::Image(100,100) || die;
  551.  
  552. This will create an image that is 100 x 100 pixels wide.  If you don't
  553. specify the dimensions, a default of 64 x 64 will be chosen.
  554.  
  555. The optional third argument, $truecolor, tells new() to create a
  556. truecolor GD::Image object.  Truecolor images have 24 bits of color
  557. data (eight bits each in the red, green and blue channels
  558. respectively), allowing for precise photograph-quality color usage.
  559. If not specified, the image will use an 8-bit palette for
  560. compatibility with older versions of libgd.
  561.  
  562. Alternatively, you may create a GD::Image object based on an existing
  563. image by providing an open filehandle, a filename, or the image data
  564. itself.  The image formats automatically recognized and accepted are:
  565. PNG, JPEG, XPM and GD2.  Other formats, including WBMP, and GD
  566. version 1, cannot be recognized automatically at this time.
  567.  
  568. If something goes wrong (e.g. insufficient memory), this call will
  569. return undef.
  570.  
  571. =item B<$image = GD::Image-E<gt>trueColor([0,1])>
  572.  
  573. For backwards compatibility with scripts previous versions of GD,
  574. new images created from scratch (width, height) are palette based
  575. by default.  To change this default to create true color images use:
  576.  
  577.     GD::Image->trueColor(1);
  578.  
  579. somewhere before creating new images.  To switch back to palette
  580. based by default, use:
  581.  
  582.     GD::Image->trueColor(0);
  583.  
  584. =item B<$image = GD::Image-E<gt>newPalette([$width,$height])>
  585.  
  586. =item B<$image = GD::Image-E<gt>newTrueColor([$width,$height])>
  587.  
  588. The newPalette() and newTrueColor() methods can be used to explicitly
  589. create an palette based or true color image regardless of the
  590. current setting of trueColor().
  591.  
  592. =item B<$image = GD::Image-E<gt>newFromPng($file, [$truecolor])>
  593.  
  594. =item B<$image = GD::Image-E<gt>newFromPngData($data, [$truecolor])>
  595.  
  596. The newFromPng() method will create an image from a PNG file read in
  597. through the provided filehandle or file path.  The filehandle must
  598. previously have been opened on a valid PNG file or pipe.  If
  599. successful, this call will return an initialized image which you can
  600. then manipulate as you please.  If it fails, which usually happens if
  601. the thing at the other end of the filehandle is not a valid PNG file,
  602. the call returns undef.  Notice that the call doesn't automatically
  603. close the filehandle for you.  But it does call C<binmode(FILEHANDLE)>
  604. for you, on platforms where this matters.
  605. The optional $truecolor (0/1) value can be used to override the global
  606. setting of trueColor() to specify if the return image should be
  607. palette-based or truecolor.
  608.  
  609. You may use any of the following as the argument:
  610.  
  611.   1) a simple filehandle, such as STDIN
  612.   2) a filehandle glob, such as *PNG
  613.   3) a reference to a glob, such as \*PNG
  614.   4) an IO::Handle object
  615.   5) the pathname of a file
  616.  
  617. In the latter case, newFromPng() will attempt to open the file for you
  618. and read the PNG information from it.
  619.  
  620.   Example1:
  621.  
  622.   open (PNG,"barnswallow.png") || die;
  623.   $myImage = newFromPng GD::Image(\*PNG) || die;
  624.   close PNG;
  625.  
  626.   Example2:
  627.   $myImage = newFromPng GD::Image('barnswallow.png');
  628.  
  629. To get information about the size and color usage of the information,
  630. you can call the image query methods described below.
  631.  
  632. The newFromPngData() method will create a new GD::Image initialized
  633. with the PNG format B<data> contained in C<$data>.
  634.  
  635. =item B<$image = GD::Image-E<gt>newFromJpeg($file, [$truecolor])>
  636.  
  637. =item B<$image = GD::Image-E<gt>newFromJpegData($data, [$truecolor])>
  638.  
  639. These methods will create an image from a JPEG file.  They work just
  640. like newFromPng() and newFromPngData(), and will accept the same
  641. filehandle and pathname arguments.
  642. The optional $truecolor (0/1) value can be used to override the global
  643. setting of trueColor() to specify if the return image should be
  644. palette-based or truecolor.
  645.  
  646. Bear in mind that JPEG is a 24-bit format, while GD is 8-bit.  This
  647. means that photographic images will become posterized.
  648.  
  649. =item B<$image = GD::Image-E<gt>newFromXbm($file)>
  650.  
  651. This works in exactly the same way as C<newFromPng>, but reads the
  652. contents of an X Bitmap (black & white) file:
  653.  
  654.     open (XBM,"coredump.xbm") || die;
  655.     $myImage = newFromXbm GD::Image(\*XBM) || die;
  656.     close XBM;
  657.  
  658. There is no newFromXbmData() function, because there is no
  659. corresponding function in the gd library.
  660.  
  661. =item B<$image = GD::Image-E<gt>newFromWMP($file)>
  662.  
  663. This creates a new GD::Image object starting from a WBMP-format file
  664. or filehandle.  There is currently no newFromWMPData() method.
  665.  
  666. =item B<$image = GD::Image-E<gt>newFromGd($file)>
  667.  
  668. =item B<$image = GD::Image-E<gt>newFromGdData($data)>
  669.  
  670. These methods initialize a GD::Image from a Gd file, filehandle, or
  671. data.  Gd is Tom Boutell's disk-based storage format, intended for the
  672. rare case when you need to read and write the image to disk quickly.
  673. It's not intended for regular use, because, unlike PNG or JPEG, no
  674. image compression is performed and these files can become B<BIG>.
  675.  
  676.     $myImage = newFromGd GD::Image("godzilla.gd") || die;
  677.     close GDF;
  678.  
  679. =item B<$image = GD::Image-E<gt>newFromGd2($file)>
  680.  
  681. =item B<$image = GD::Image-E<gt>newFromGd2Data($data)>
  682.  
  683. This works in exactly the same way as C<newFromGd()> and
  684. newFromGdData, but use the new compressed GD2 image format.
  685.  
  686. =item B<$image = GD::Image-E<gt>newFromGd2Part($file,srcX,srcY,width,height)>
  687.  
  688. This class method allows you to read in just a portion of a GD2 image
  689. file.  In additionto a filehandle, it accepts the top-left corner and
  690. dimensions (width,height) of the region of the image to read.  For
  691. example:
  692.  
  693.     open (GDF,"godzilla.gd2") || die;
  694.     $myImage = GD::Image->newFromGd2Part(\*GDF,10,20,100,100) || die;
  695.     close GDF;
  696.  
  697. This reads a 100x100 square portion of the image starting from
  698. position (10,20).
  699.  
  700. =item B<$image = GD::Image-E<gt>newFromXpm($filename)>
  701.  
  702. This creates a new GD::Image object starting from a B<filename>.  This
  703. is unlike the other newFrom() functions because it does not take a
  704. filehandle.  This difference comes from an inconsistency in the
  705. underlying gd library.
  706.  
  707.     $myImage = newFromXpm GD::Image('earth.xpm') || die;
  708.  
  709. This function is only available if libgd was compiled with XPM
  710. support.  
  711.  
  712. NOTE: The libgd library is unable to read certain XPM files, returning
  713. an all-black image instead.
  714.  
  715. =head1 GD::Image Methods
  716.  
  717. Once a GD::Image object is created, you can draw with it, copy it, and
  718. merge two images.  When you are finished manipulating the object, you
  719. can convert it into a standard image file format to output or save to
  720. a file.
  721.  
  722. =head2 Image Data Output Methods
  723.  
  724. The following methods convert the internal drawing format into
  725. standard output file formats.
  726.  
  727. =item B<$pngdata = $image-E<gt>png([$compression_level])>
  728.  
  729. This returns the image data in PNG format.  You can then print it,
  730. pipe it to a display program, or write it to a file.  Example:
  731.  
  732.     $png_data = $myImage->png;
  733.     open (DISPLAY,"| display -") || die;
  734.     binmode DISPLAY;
  735.     print DISPLAY $png_data;
  736.     close DISPLAY;
  737.  
  738. Note the use of C<binmode()>.  This is crucial for portability to
  739. DOSish platforms.
  740.  
  741. The optional $compression_level argument controls the amount of
  742. compression to apply to the output PNG image.  Values range from 0-9,
  743. where 0 means no compression (largest files, highest quality) and 9
  744. means maximum compression (smallest files, worst quality).  A
  745. compression level of -1 uses the default compression level selected
  746. when zlib was compiled on your system, and is the same as calling
  747. png() with no argument.  Be careful not to confuse this argument with
  748. the jpeg() quality argument, which ranges from 0-100 and has the
  749. opposite meaning from compression (higher numbers give higher
  750. quality).
  751.  
  752. =item B<$jpegdata = $image-E<gt>jpeg([$quality])>
  753.  
  754. This returns the image data in JPEG format.  You can then print it,
  755. pipe it to a display program, or write it to a file.  You may pass an
  756. optional quality score to jpeg() in order to control the JPEG quality.
  757. This should be an integer between 0 and 100.  Higher quality scores
  758. give larger files and better image quality.  If you don't specify the
  759. quality, jpeg() will choose a good default.
  760.  
  761. =item B<$gddata = $image-E<gt>gd>
  762.  
  763. This returns the image data in GD format.  You can then print it,
  764. pipe it to a display program, or write it to a file.  Example:
  765.  
  766.     binmode MYOUTFILE;
  767.     print MYOUTFILE $myImage->gd;
  768.  
  769. =item B<$gd2data = $image-E<gt>gd2>
  770.  
  771. Same as gd(), except that it returns the data in compressed GD2
  772. format.
  773.  
  774. =item B<$wbmpdata = $image-E<gt>wbmp([$foreground])>
  775.  
  776. This returns the image data in WBMP format, which is a black-and-white
  777. image format.  Provide the index of the color to become the foreground
  778. color.  All other pixels will be considered background.
  779.  
  780. =back
  781.  
  782. =head2 Color Control
  783.  
  784. These methods allow you to control and manipulate the GD::Image color
  785. table.
  786.  
  787. =over 4
  788.  
  789. =item B<$index = $image-E<gt>colorAllocate(red,green,blue)>
  790.  
  791. This allocates a color with the specified red, green and blue
  792. components and returns its index in the color table, if specified.
  793. The first color allocated in this way becomes the image's background
  794. color.  (255,255,255) is white (all pixels on).  (0,0,0) is black (all
  795. pixels off).  (255,0,0) is fully saturated red.  (127,127,127) is 50%
  796. gray.  You can find plenty of examples in /usr/X11/lib/X11/rgb.txt.
  797.  
  798. If no colors are allocated, then this function returns -1.
  799.  
  800. Example:
  801.  
  802.     $white = $myImage->colorAllocate(0,0,0); #background color
  803.     $black = $myImage->colorAllocate(255,255,255);
  804.     $peachpuff = $myImage->colorAllocate(255,218,185);
  805.  
  806. =item B<$index = $image-E<gt>colorAllocateAlpha(reg,green,blue,alpha)>
  807.  
  808. This allocates a color with the specified red, green, and blue components,
  809. plus the specified alpha channel.  The alpha value may range from 0 (opaque)
  810. to 127 (transparent).  The C<alphaBlending> function changes the way this
  811. alpha channel affects the resulting image.
  812.  
  813. =item B<$index = $image-E<gt>colorAllocateAlpha(reg,green,blue,alpha)>
  814.  
  815. This allocates a color with the specified red, green, and blue components,
  816. plus the specified alpha channel.  The alpha value may range from 0 (opaque)
  817. to 127 (transparent).  The C<alphaBlending> function changes the way this
  818. alpha channel affects the resulting image.
  819.  
  820. =item B<$image-E<gt>colorDeallocate(colorIndex)>
  821.  
  822. This marks the color at the specified index as being ripe for
  823. reallocation.  The next time colorAllocate is used, this entry will be
  824. replaced.  You can call this method several times to deallocate
  825. multiple colors.  There's no function result from this call.
  826.  
  827. Example:
  828.  
  829.     $myImage->colorDeallocate($peachpuff);
  830.     $peachy = $myImage->colorAllocate(255,210,185);
  831.  
  832. =item B<$index = $image-E<gt>colorClosest(red,green,blue)>
  833.  
  834. This returns the index of the color closest in the color table to the
  835. red green and blue components specified.  If no colors have yet been
  836. allocated, then this call returns -1.
  837.  
  838. Example:
  839.  
  840.     $apricot = $myImage->colorClosest(255,200,180);
  841.  
  842. =item B<$index = $image-E<gt>colorClosestHWB(red,green,blue)>
  843.  
  844. This also attempts to return the color closest in the color table to the
  845. red green and blue components specified. If uses a Hue/White/Black 
  846. color representation to make the selected colour more likely to match
  847. human perceptions of similar colors.
  848.  
  849. If no colors have yet been
  850. allocated, then this call returns -1.
  851.  
  852. Example:
  853.  
  854.     $mostred = $myImage->colorClosestHWB(255,0,0);
  855.  
  856. =item B<$index = $image-E<gt>colorExact(red,green,blue)>
  857.  
  858. This returns the index of a color that exactly matches the specified
  859. red green and blue components.  If such a color is not in the color
  860. table, this call returns -1.
  861.  
  862.     $rosey = $myImage->colorExact(255,100,80);
  863.     warn "Everything's coming up roses.\n" if $rosey >= 0;
  864.  
  865. =item B<$index = $image-E<gt>colorResolve(red,green,blue)>
  866.  
  867. This returns the index of a color that exactly matches the specified
  868. red green and blue components.  If such a color is not in the color
  869. table and there is room, then this method allocates the color in the
  870. color table and returns its index.
  871.  
  872.     $rosey = $myImage->colorResolve(255,100,80);
  873.     warn "Everything's coming up roses.\n" if $rosey >= 0;
  874.  
  875. =item B<$colorsTotal = $image-E<gt>colorsTotal)> I<object method>
  876.  
  877. This returns the total number of colors allocated in the object.
  878.  
  879.     $maxColors = $myImage->colorsTotal;
  880.  
  881. =item B<$index = $image-E<gt>getPixel(x,y)> I<object method>
  882.  
  883. This returns the color table index underneath the specified
  884. point.  It can be combined with rgb()
  885. to obtain the rgb color underneath the pixel.
  886.  
  887. Example:
  888.  
  889.         $index = $myImage->getPixel(20,100);
  890.         ($r,$g,$b) = $myImage->rgb($index);
  891.  
  892. =item B<($red,$green,$blue) = $image-E<gt>rgb($index)>
  893.  
  894. This returns a list containing the red, green and blue components of
  895. the specified color index.
  896.  
  897. Example:
  898.  
  899.     @RGB = $myImage->rgb($peachy);
  900.  
  901. =item B<$image-E<gt>transparent($colorIndex)>
  902.  
  903. This marks the color at the specified index as being transparent.
  904. Portions of the image drawn in this color will be invisible.  This is
  905. useful for creating paintbrushes of odd shapes, as well as for
  906. making PNG backgrounds transparent for displaying on the Web.  Only
  907. one color can be transparent at any time. To disable transparency, 
  908. specify -1 for the index.  
  909.  
  910. If you call this method without any parameters, it will return the
  911. current index of the transparent color, or -1 if none.
  912.  
  913. Example:
  914.  
  915.     open(PNG,"test.png");
  916.     $im = newFromPng GD::Image(PNG);
  917.     $white = $im->colorClosest(255,255,255); # find white
  918.     $im->transparent($white);
  919.     binmode STDOUT;
  920.     print $im->png;
  921.  
  922. =back
  923.  
  924. =head2 Special Colors
  925.  
  926. GD implements a number of special colors that can be used to achieve
  927. special effects.  They are constants defined in the GD::
  928. namespace, but automatically exported into your namespace when the GD
  929. module is loaded.
  930.  
  931. =over 4
  932.  
  933. =item B<$image-E<gt>setBrush($image)>
  934.  
  935. You can draw lines and shapes using a brush pattern.  Brushes are just
  936. images that you can create and manipulate in the usual way. When you
  937. draw with them, their contents are used for the color and shape of the
  938. lines.
  939.  
  940. To make a brushed line, you must create or load the brush first, then
  941. assign it to the image using setBrush().  You can then draw in that
  942. with that brush using the B<gdBrushed> special color.  It's often
  943. useful to set the background of the brush to transparent so that the
  944. non-colored parts don't overwrite other parts of your image.
  945.  
  946. Example:
  947.  
  948.     # Create a brush at an angle
  949.     $diagonal_brush = new GD::Image(5,5);
  950.     $white = $diagonal_brush->colorAllocate(255,255,255);
  951.     $black = $diagonal_brush->colorAllocate(0,0,0);
  952.     $diagonal_brush->transparent($white);
  953.     $diagonal_brush->line(0,4,4,0,$black); # NE diagonal
  954.  
  955.     # Set the brush
  956.     $myImage->setBrush($diagonal_brush);
  957.     
  958.     # Draw a circle using the brush
  959.     $myImage->arc(50,50,25,25,0,360,gdBrushed);
  960.  
  961. =item B<$image-E<gt>setThickness($thickness)>
  962.  
  963. Lines drawn with line(), rectangle(), arc(), and so forth are 1 pixel
  964. thick by default.  Call setThickness() to change the line drawing
  965. width.
  966.  
  967. =item B<$image-E<gt>setStyle(@colors)>
  968.  
  969. Styled lines consist of an arbitrary series of repeated colors and are
  970. useful for generating dotted and dashed lines.  To create a styled
  971. line, use setStyle() to specify a repeating series of colors.  It
  972. accepts an array consisting of one or more color indexes.  Then draw
  973. using the B<gdStyled> special color.  Another special color,
  974. B<gdTransparent> can be used to introduce holes in the line, as the
  975. example shows.
  976.  
  977. Example:
  978.  
  979.     # Set a style consisting of 4 pixels of yellow,
  980.     # 4 pixels of blue, and a 2 pixel gap
  981.     $myImage->setStyle($yellow,$yellow,$yellow,$yellow,
  982.                $blue,$blue,$blue,$blue,
  983.                gdTransparent,gdTransparent);
  984.     $myImage->arc(50,50,25,25,0,360,gdStyled);
  985.  
  986. To combine the C<gdStyled> and C<gdBrushed> behaviors, you can specify
  987. C<gdStyledBrushed>.  In this case, a pixel from the current brush
  988. pattern is rendered wherever the color specified in setStyle() is
  989. neither gdTransparent nor 0.
  990.  
  991. =item B<gdTiled>
  992.  
  993. Draw filled shapes and flood fills using a pattern.  The pattern is
  994. just another image.  The image will be tiled multiple times in order
  995. to fill the required space, creating wallpaper effects.  You must call
  996. C<setTile> in order to define the particular tile pattern you'll use
  997. for drawing when you specify the gdTiled color.
  998. details.
  999.  
  1000. =item B<gdStyled>
  1001.  
  1002. The gdStyled color is used for creating dashed and dotted lines.  A
  1003. styled line can contain any series of colors and is created using the
  1004. setStyled() command.
  1005.  
  1006. =item B<gdAntiAliased>
  1007.  
  1008. The C<gdAntiAliased> color is used for drawing lines with antialiasing
  1009. turned on.  Antialiasing will blend the jagged edges of lines with the
  1010. background, creating a smoother look.  The actual color drawn is set
  1011. with setAntiAliased().
  1012.  
  1013. =item B<$image-E<gt>setAntiAliased($color)>
  1014.  
  1015. "Antialiasing" is a process by which jagged edges associated with line
  1016. drawing can be reduced by blending the foreground color with an
  1017. appropriate percentage of the background, depending on how much of the
  1018. pixel in question is actually within the boundaries of the line being
  1019. drawn. All line-drawing methods, such as line() and polygon, will draw
  1020. antialiased lines if the special "color" B<gdAntiAliased> is used when
  1021. calling them.
  1022.  
  1023. setAntiAliased() is used to specify the actual foreground color to be
  1024. used when drawing antialiased lines. You may set any color to be the
  1025. foreground, however as of libgd version 2.0.12 an alpha channel component is
  1026. not supported.
  1027.  
  1028. Antialiased lines can be drawn on both truecolor and palette-based
  1029. images. However, attempts to draw antialiased lines on highly complex
  1030. palette-based backgrounds may not give satisfactory results, due to
  1031. the limited number of colors available in the palette. Antialiased
  1032. line-drawing on simple backgrounds should work well with palette-based
  1033. images; otherwise create or fetch a truecolor image instead.
  1034.  
  1035. =item B<$image-E<gt>setAntiAliasedDontBlend($color,[$flag])>
  1036.  
  1037. Normally, when drawing lines with the special B<gdAntiAliased>
  1038. "color," blending with the background to reduce jagged edges is the
  1039. desired behavior. However, when it is desired that lines not be
  1040. blended with one particular color when it is encountered in the
  1041. background, the setAntiAliasedDontBlend() method can be used to
  1042. indicate the special color that the foreground should stand out more
  1043. clearly against.
  1044.  
  1045. Once turned on, you can turn this feature off by calling
  1046. setAntiAliasedDontBlend() with a second argument of 0:
  1047.  
  1048.  $image->setAntiAliasedDontBlend($color,0);
  1049.  
  1050. =back
  1051.  
  1052. =head2 Drawing Commands
  1053.  
  1054. These methods allow you to draw lines, rectangles, and elipses, as
  1055. well as to perform various special operations like flood-fill.
  1056.  
  1057. =over 4
  1058.  
  1059. =item B<$image-E<gt>setPixel($x,$y,$color)>
  1060.  
  1061. This sets the pixel at (x,y) to the specified color index.  No value
  1062. is returned from this method.  The coordinate system starts at the
  1063. upper left at (0,0) and gets larger as you go down and to the right.
  1064. You can use a real color, or one of the special colors gdBrushed, 
  1065. gdStyled and gdStyledBrushed can be specified.
  1066.  
  1067. Example:
  1068.  
  1069.     # This assumes $peach already allocated
  1070.     $myImage->setPixel(50,50,$peach);
  1071.  
  1072. =item B<$image-E<gt>line($x1,$y1,$x2,$y2,$color)>
  1073.  
  1074. This draws a line from (x1,y1) to (x2,y2) of the specified color.  You
  1075. can use a real color, or one of the special colors gdBrushed, 
  1076. gdStyled and gdStyledBrushed.
  1077.  
  1078. Example:
  1079.  
  1080.     # Draw a diagonal line using the currently defind
  1081.     # paintbrush pattern.
  1082.     $myImage->line(0,0,150,150,gdBrushed);
  1083.  
  1084. =item B<$image-E<gt>dashedLine($x1,$y1,$x2,$y2,$color)>
  1085.  
  1086. This draws a dashed line from (x1,y1) to (x2,y2) in the specified
  1087. color.  A more powerful way to generate arbitrary dashed and dotted
  1088. lines is to use the setStyle() method described below and to draw with
  1089. the special color gdStyled.
  1090.  
  1091. Example:
  1092.  
  1093.     $myImage->dashedLine(0,0,150,150,$blue);
  1094.  
  1095. =item B<GD::Image::rectangle($x1,$y1,$x2,$y2,$color)>
  1096.  
  1097. This draws a rectangle with the specified color.  (x1,y1) and (x2,y2)
  1098. are the upper left and lower right corners respectively.  Both real
  1099. color indexes and the special colors gdBrushed, gdStyled and
  1100. gdStyledBrushed are accepted.
  1101.  
  1102. Example:
  1103.  
  1104.     $myImage->rectangle(10,10,100,100,$rose);
  1105.  
  1106. =item B<$image-E<gt>filledRectangle($x1,$y1,$x2,$y2,$color)>
  1107.  
  1108. This draws a rectangle filed with the specified color.  You can use a
  1109. real color, or the special fill color gdTiled to fill the polygon
  1110. with a pattern.
  1111.  
  1112. Example:
  1113.  
  1114.     # read in a fill pattern and set it
  1115.     $tile = newFromPng GD::Image('happyface.png');
  1116.     $myImage->setTile($tile); 
  1117.  
  1118.     # draw the rectangle, filling it with the pattern
  1119.     $myImage->filledRectangle(10,10,150,200,gdTiled);
  1120.  
  1121. =item B<$image-E<gt>polygon($polygon,$color)>
  1122.  
  1123. This draws a polygon with the specified color.  The polygon must be
  1124. created first (see below).  The polygon must have at least three
  1125. vertices.  If the last vertex doesn't close the polygon, the method
  1126. will close it for you.  Both real color indexes and the special 
  1127. colors gdBrushed, gdStyled and gdStyledBrushed can be specified.
  1128.  
  1129. Example:
  1130.  
  1131.     $poly = new GD::Polygon;
  1132.     $poly->addPt(50,0);
  1133.     $poly->addPt(99,99);
  1134.     $poly->addPt(0,99);
  1135.     $myImage->polygon($poly,$blue);
  1136.  
  1137. =item B<$image-E<gt>filledPolygon($poly,$color)>
  1138.  
  1139. This draws a polygon filled with the specified color.  You can use a
  1140. real color, or the special fill color gdTiled to fill the polygon
  1141. with a pattern.
  1142.  
  1143. Example:
  1144.  
  1145.     # make a polygon
  1146.     $poly = new GD::Polygon;
  1147.     $poly->addPt(50,0);
  1148.     $poly->addPt(99,99);
  1149.     $poly->addPt(0,99);
  1150.  
  1151.     # draw the polygon, filling it with a color
  1152.     $myImage->filledPolygon($poly,$peachpuff);
  1153.  
  1154. =item B<$image-E<gt>ellipse($cx,$cy,$width,$height,$color)>
  1155.  
  1156. =item B<$image-E<gt>filledEllipse($cx,$cy,$width,$height,$color)>
  1157.  
  1158. These methods() draw ellipses. ($cx,$cy) is the center of the arc, and
  1159. ($width,$height) specify the ellipse width and height, respectively.
  1160. filledEllipse() is like Ellipse() except that the former produces
  1161. filled versions of the ellipse.
  1162.  
  1163. =item B<$image-E<gt>arc($cx,$cy,$width,$height,$start,$end,$color)>
  1164.  
  1165. This draws arcs and ellipses.  (cx,cy) are the center of the arc, and
  1166. (width,height) specify the width and height, respectively.  The
  1167. portion of the ellipse covered by the arc are controlled by start and
  1168. end, both of which are given in degrees from 0 to 360.  Zero is at the
  1169. top of the ellipse, and angles increase clockwise.  To specify a
  1170. complete ellipse, use 0 and 360 as the starting and ending angles.  To
  1171. draw a circle, use the same value for width and height.
  1172.  
  1173. You can specify a normal color or one of the special colors
  1174. B<gdBrushed>, B<gdStyled>, or B<gdStyledBrushed>.
  1175.  
  1176. Example:
  1177.  
  1178.     # draw a semicircle centered at 100,100
  1179.     $myImage->arc(100,100,50,50,0,180,$blue);
  1180.  
  1181. =item B<$image-E<gt>filledArc($cx,$cy,$width,$height,$start,$end,$color [,$arc_style])>
  1182.  
  1183. This method is like arc() except that it colors in the pie wedge with
  1184. the selected color.  $arc_style is optional.  If present it is a
  1185. bitwise OR of the following constants:
  1186.  
  1187.   gdArc           connect start & end points of arc with a rounded edge
  1188.   gdChord         connect start & end points of arc with a straight line
  1189.   gdPie           synonym for gdChord
  1190.   gdNoFill        outline the arc or chord
  1191.   gdEdged         connect beginning and ending of the arc to the center
  1192.  
  1193. gdArc and gdChord are mutally exclusive.  gdChord just connects the
  1194. starting and ending angles with a straight line, while gdArc produces
  1195. a rounded edge. gdPie is a synonym for gdArc. gdNoFill indicates that
  1196. the arc or chord should be outlined, not filled. gdEdged, used
  1197. together with gdNoFill, indicates that the beginning and ending angles
  1198. should be connected to the center; this is a good way to outline
  1199. (rather than fill) a "pie slice."
  1200.  
  1201. Example:
  1202.  
  1203.   $image->filledArc(100,100,50,50,0,90,$blue,gdEdged|gdNoFill);
  1204.  
  1205. =item B<$image-E<gt>fill($x,$y,$color)>
  1206.  
  1207. This method flood-fills regions with the specified color.  The color
  1208. will spread through the image, starting at point (x,y), until it is
  1209. stopped by a pixel of a different color from the starting pixel (this
  1210. is similar to the "paintbucket" in many popular drawing toys).  You
  1211. can specify a normal color, or the special color gdTiled, to flood-fill
  1212. with patterns.
  1213.  
  1214. Example:
  1215.  
  1216.     # Draw a rectangle, and then make its interior blue
  1217.     $myImage->rectangle(10,10,100,100,$black);
  1218.     $myImage->fill(50,50,$blue);
  1219.  
  1220. =item B<$image-E<gt>fillToBorder($x,$y,$bordercolor,$color)>
  1221.  
  1222. Like C<fill>, this method flood-fills regions with the specified
  1223. color, starting at position (x,y).  However, instead of stopping when
  1224. it hits a pixel of a different color than the starting pixel, flooding
  1225. will only stop when it hits the color specified by bordercolor.  You
  1226. must specify a normal indexed color for the bordercolor.  However, you
  1227. are free to use the gdTiled color for the fill.
  1228.  
  1229. Example:
  1230.  
  1231.     # This has the same effect as the previous example
  1232.     $myImage->rectangle(10,10,100,100,$black);
  1233.     $myImage->fillToBorder(50,50,$black,$blue);
  1234.  
  1235. =back
  1236.  
  1237.  
  1238.  
  1239. =head2 Image Copying Commands
  1240.  
  1241. Two methods are provided for copying a rectangular region from one
  1242. image to another.  One method copies a region without resizing it.
  1243. The other allows you to stretch the region during the copy operation.
  1244.  
  1245. With either of these methods it is important to know that the routines
  1246. will attempt to flesh out the destination image's color table to match
  1247. the colors that are being copied from the source.  If the
  1248. destination's color table is already full, then the routines will
  1249. attempt to find the best match, with varying results.
  1250.  
  1251. =over 4
  1252.  
  1253. =item B<$image-E<gt>copy($sourceImage,$dstX,$dstY,>
  1254.  
  1255. B<                $srcX,$srcY,$width,$height)>
  1256.  
  1257. This is the simplest of the several copy operations, copying the
  1258. specified region from the source image to the destination image (the
  1259. one performing the method call).  (srcX,srcY) specify the upper left
  1260. corner of a rectangle in the source image, and (width,height) give the
  1261. width and height of the region to copy.  (dstX,dstY) control where in
  1262. the destination image to stamp the copy.  You can use the same image
  1263. for both the source and the destination, but the source and
  1264. destination regions must not overlap or strange things will happen.
  1265.  
  1266. Example:
  1267.  
  1268.     $myImage = new GD::Image(100,100);
  1269.     ... various drawing stuff ...
  1270.     $srcImage = new GD::Image(50,50);
  1271.     ... more drawing stuff ...
  1272.     # copy a 25x25 pixel region from $srcImage to
  1273.     # the rectangle starting at (10,10) in $myImage
  1274.     $myImage->copy($srcImage,10,10,0,0,25,25);
  1275.  
  1276. =item B<$image-E<gt>clone()>
  1277.  
  1278. Make a copy of the image and return it as a new object.  The new image
  1279. will look identical.  However, it may differ in the size of the color
  1280. palette and other nonessential details.
  1281.  
  1282. Example:
  1283.  
  1284.     $myImage = new GD::Image(100,100);
  1285.     ... various drawing stuff ...
  1286.         $copy = $myImage->clone;
  1287.  
  1288. =item B<$image-E<gt>copyMerge($sourceImage,$dstX,$dstY,>
  1289.  
  1290. B<                $srcX,$srcY,$width,$height,$percent)>
  1291.  
  1292. This copies the indicated rectangle from the source image to the
  1293. destination image, merging the colors to the extent specified by
  1294. percent (an integer between 0 and 100).  Specifying 100% has the same
  1295. effect as copy() -- replacing the destination pixels with the source
  1296. image.  This is most useful for highlighting an area by merging in a
  1297. solid rectangle.
  1298.  
  1299. Example:
  1300.  
  1301.     $myImage = new GD::Image(100,100);
  1302.     ... various drawing stuff ...
  1303.     $redImage = new GD::Image(50,50);
  1304.     ... more drawing stuff ...
  1305.     # copy a 25x25 pixel region from $srcImage to
  1306.     # the rectangle starting at (10,10) in $myImage, merging 50%
  1307.     $myImage->copyMerge($srcImage,10,10,0,0,25,25,50);
  1308.  
  1309. =item B<$image-E<gt>copyMergeGray($sourceImage,$dstX,$dstY,>
  1310.  
  1311. B<                $srcX,$srcY,$width,$height,$percent)>
  1312.  
  1313. This is identical to copyMerge() except that it preserves the hue of
  1314. the source by converting all the pixels of the destination rectangle
  1315. to grayscale before merging.
  1316.  
  1317. =item B<$image-E<gt>copyResized($sourceImage,$dstX,$dstY,>
  1318.  
  1319. B<                $srcX,$srcY,$destW,$destH,$srcW,$srcH)>
  1320.  
  1321. This method is similar to copy() but allows you to choose different
  1322. sizes for the source and destination rectangles.  The source and
  1323. destination rectangle's are specified independently by (srcW,srcH) and
  1324. (destW,destH) respectively.  copyResized() will stretch or shrink the
  1325. image to accomodate the size requirements.
  1326.  
  1327. Example:
  1328.  
  1329.     $myImage = new GD::Image(100,100);
  1330.     ... various drawing stuff ...
  1331.     $srcImage = new GD::Image(50,50);
  1332.     ... more drawing stuff ...
  1333.     # copy a 25x25 pixel region from $srcImage to
  1334.     # a larger rectangle starting at (10,10) in $myImage
  1335.     $myImage->copyResized($srcImage,10,10,0,0,50,50,25,25);
  1336.  
  1337. =item B<$image-E<gt>copyResampled($sourceImage,$dstX,$dstY,>
  1338.  
  1339. B<                $srcX,$srcY,$destW,$destH,$srcW,$srcH)>
  1340.  
  1341. This method is similar to copyResized() but provides "smooth" copying
  1342. from a large image to a smaller one, using a weighted average of the
  1343. pixels of the source area rather than selecting one representative
  1344. pixel. This method is identical to copyResized() when the destination
  1345. image is a palette image.
  1346.  
  1347. =item B<$image-E<gt>trueColorToPalette([$dither], [$colors])>
  1348.  
  1349. This method converts a truecolor image to a palette image. The code for
  1350. this function was originally drawn from the Independent JPEG Group library
  1351. code, which is excellent. The code has been modified to preserve as much
  1352. alpha channel information as possible in the resulting palette, in addition
  1353. to preserving colors as well as possible. This does not work as well as
  1354. might be hoped. It is usually best to simply produce a truecolor
  1355. output image instead, which guarantees the highest output quality.
  1356. Both the dithering (0/1, default=0) and maximum number of colors used
  1357. (<=256, default = gdMaxColors) can be specified.
  1358.  
  1359. =back
  1360.  
  1361. =head2 Image Transformation Commands
  1362.  
  1363. Gd also provides some common image transformations:
  1364.  
  1365. =over 4
  1366.  
  1367. =item B<$image = $sourceImage-E<gt>copyRotate90()>
  1368.  
  1369. =item B<$image = $sourceImage-E<gt>copyRotate180()>
  1370.  
  1371. =item B<$image = $sourceImage-E<gt>copyRotate270()>
  1372.  
  1373. =item B<$image = $sourceImage-E<gt>copyFlipHorizontal()>
  1374.  
  1375. =item B<$image = $sourceImage-E<gt>copyFlipVertical()>
  1376.  
  1377. =item B<$image = $sourceImage-E<gt>copyTranspose()>
  1378.  
  1379. =item B<$image = $sourceImage-E<gt>copyReverseTranspose()>
  1380.  
  1381. These methods can be used to rotate, flip, or transpose an image.
  1382. The result of the method is a copy of the image.
  1383.  
  1384. =item B<$image-E<gt>rotate180()>
  1385.  
  1386. =item B<$image-E<gt>flipHorizontal()>
  1387.  
  1388. =item B<$image-E<gt>flipVertical()>
  1389.  
  1390. These methods are similar to the copy* versions, but instead
  1391. modify the image in place.
  1392.  
  1393. =back
  1394.  
  1395. =head2 Character and String Drawing
  1396.  
  1397. Gd allows you to draw characters and strings, either in normal
  1398. horizontal orientation or rotated 90 degrees.  These routines use a
  1399. GD::Font object, described in more detail below.  There are four
  1400. built-in fonts, available in global variables B<gdGiantFont>,
  1401. B<gdLargeFont>, B<gdMediumBoldFont>, B<gdSmallFont> and B<gdTinyFont>.
  1402. Currently there is no way of dynamically creating your own fonts.
  1403.  
  1404. =over 4
  1405.  
  1406. =item B<$image-E<gt>string($font,$x,$y,$string,$color)>
  1407.  
  1408. This method draws a string startin at position (x,y) in the specified
  1409. font and color.  Your choices of fonts are gdSmallFont, gdMediumBoldFont,
  1410. gdTinyFont, gdLargeFont and gdGiantFont.
  1411.  
  1412. Example:
  1413.  
  1414.     $myImage->string(gdSmallFont,2,10,"Peachy Keen",$peach);
  1415.  
  1416. =item B<$image-E<gt>stringUp($font,$x,$y,$string,$color)>
  1417.  
  1418. Just like the previous call, but draws the text rotated
  1419. counterclockwise 90 degrees.
  1420.  
  1421. =item B<$image-E<gt>char($font,$x,$y,$char,$color)>
  1422.  
  1423. =item B<$image-E<gt>charUp($font,$x,$y,$char,$color)>
  1424.  
  1425. These methods draw single characters at position (x,y) in the
  1426. specified font and color.  They're carry-overs from the C interface,
  1427. where there is a distinction between characters and strings.  Perl is
  1428. insensible to such subtle distinctions.
  1429.  
  1430. =item B<@bounds = $image-E<gt>stringFT($fgcolor,$fontname,$ptsize,$angle,$x,$y,$string)>
  1431.  
  1432. =item B<@bounds = GD::Image-E<gt>stringFT($fgcolor,$fontname,$ptsize,$angle,$x,$y,$string)>
  1433.  
  1434. =item B<@bounds = $image-E<gt>stringFT($fgcolor,$fontname,$ptsize,$angle,$x,$y,$string,\%options)>
  1435.  
  1436. This method uses TrueType to draw a scaled, antialiased string using
  1437. the TrueType vector font of your choice.  It requires that libgd to
  1438. have been compiled with TrueType support, and for the appropriate
  1439. TrueType font to be installed on your system.
  1440.  
  1441. The arguments are as follows:
  1442.  
  1443.   fgcolor    Color index to draw the string in
  1444.   fontname   An absolute path to the TrueType (.ttf) font file
  1445.   ptsize     The desired point size (may be fractional)
  1446.   angle      The rotation angle, in radians
  1447.   x,y        X and Y coordinates to start drawing the string
  1448.   string     The string itself
  1449.  
  1450. If successful, the method returns an eight-element list giving the
  1451. boundaries of the rendered string:
  1452.  
  1453.  @bounds[0,1]  Lower left corner (x,y)
  1454.  @bounds[2,3]  Lower right corner (x,y)
  1455.  @bounds[4,5]  Upper right corner (x,y)
  1456.  @bounds[6,7]  Upper left corner (x,y)
  1457.  
  1458. In case of an error (such as the font not being available, or FT
  1459. support not being available), the method returns an empty list and
  1460. sets $@ to the error message.
  1461.  
  1462. You may also call this method from the GD::Image class name, in which
  1463. case it doesn't do any actual drawing, but returns the bounding box
  1464. using an inexpensive operation.  You can use this to perform layout
  1465. operations prior to drawing.
  1466.  
  1467. Using a negative color index will disable anti-aliasing, as described
  1468. in the libgd manual page at
  1469. L<http://www.boutell.com/gd/manual2.0.9.html#gdImageStringFT>.
  1470.  
  1471. An optional 8th argument allows you to pass a hashref of options to
  1472. stringFT().  Two hashkeys are recognized: B<linespacing>, if present,
  1473. controls the spacing between lines of text.  B<charmap>, if present,
  1474. sets the character map to use.
  1475.  
  1476. The value of B<linespacing> is supposed to be a multiple of the
  1477. character height, so setting linespacing to 2.0 will result in
  1478. double-spaced lines of text.  However the current version of libgd
  1479. (2.0.12) does not do this.  Instead the linespacing seems to be double
  1480. what is provided in this argument.  So use a spacing of 0.5 to get
  1481. separation of exactly one line of text.  In practice, a spacing of 0.6
  1482. seems to give nice results.  Another thing to watch out for is that
  1483. successive lines of text should be separated by the "\r\n" characters,
  1484. not just "\n".
  1485.  
  1486. The value of B<charmap> is one of "Unicode", "Shift_JIS" and "Big5".
  1487. The interaction between Perl, Unicode and libgd is not clear to me,
  1488. and you should experiment a bit if you want to use this feature.
  1489.  
  1490. Example:
  1491.  
  1492.  $gd->stringFT($black,'/dosc/windows/Fonts/pala.ttf',40,0,20,90,
  1493.               "hi there\r\nbye now",
  1494.           {linespacing=>0.6,
  1495.            charmap  => 'Unicode',
  1496.           });
  1497.  
  1498. For backward compatibility with older versions of the FreeType
  1499. library, the alias stringTTF() is also recognized.  Also be aware that
  1500. relative font paths are not recognized due to problems in the libgd
  1501. library.
  1502.  
  1503. =back
  1504.  
  1505. =head2 Alpha channels
  1506.  
  1507. The alpha channel methods allow you to control the way drawings are
  1508. processed according to the alpha channel. When true color is turned
  1509. on, colors are encoded as four bytes, in which the last three bytes
  1510. are the RGB color values, and the first byte is the alpha channel.
  1511. Therefore the hexadecimal representation of a non transparent RGB
  1512. color will be: C=0x00(rr)(bb)(bb)
  1513.  
  1514. When alpha blending is turned on, you can use the first byte of the
  1515. color to control the transparency, meaning that a rectangle painted
  1516. with color 0x00(rr)(bb)(bb) will be opaque, and another one painted
  1517. with 0x7f(rr)(gg)(bb) will be transparent. The Alpha value must be >=
  1518. 0 and <= 0x7f.
  1519.  
  1520. =over 4
  1521.  
  1522. =item B<$image-E<gt>alphaBlending($blending)>
  1523.  
  1524. The alphaBlending() method allows for two different modes of drawing
  1525. on truecolor images. In blending mode, which is on by default (libgd
  1526. 2.0.2 and above), the alpha channel component of the color supplied to
  1527. all drawing functions, such as C<setPixel>, determines how much of the
  1528. underlying color should be allowed to shine through. As a result, GD
  1529. automatically blends the existing color at that point with the drawing
  1530. color, and stores the result in the image. The resulting pixel is
  1531. opaque. In non-blending mode, the drawing color is copied literally
  1532. with its alpha channel information, replacing the destination
  1533. pixel. Blending mode is not available when drawing on palette images.
  1534.  
  1535. =item B<$image-E<gt>saveAlpha($saveAlpha)>
  1536.  
  1537. By default, GD (libgd 2.0.2 and above) does not attempt to save full
  1538. alpha channel information (as opposed to single-color transparency)
  1539. when saving PNG images. (PNG is currently the only output format
  1540. supported by gd which can accommodate alpa channel information.) This
  1541. saves space in the output file. If you wish to create an image with
  1542. alpha channel information for use with tools that support it, call
  1543. C<saveAlpha(1)> to turn on saving of such information, and call
  1544. C<alphaBlending(0)> to turn off alpha blending within the library so
  1545. that alpha channel information is actually stored in the image rather
  1546. than being composited immediately at the time that drawing functions
  1547. are invoked.
  1548.  
  1549. =back
  1550.  
  1551.  
  1552. =head2 Miscellaneous Image Methods
  1553.  
  1554. These are various utility methods that are useful in some
  1555. circumstances.
  1556.  
  1557. =over 4
  1558.  
  1559. =item B<$image-E<gt>interlaced([$flag])>
  1560.  
  1561. This method sets or queries the image's interlaced setting.  Interlace
  1562. produces a cool venetian blinds effect on certain viewers.  Provide a
  1563. true parameter to set the interlace attribute.  Provide undef to
  1564. disable it.  Call the method without parameters to find out the
  1565. current setting.
  1566.  
  1567. =item B<($width,$height) = $image-E<gt>getBounds()>
  1568.  
  1569. This method will return a two-member list containing the width and
  1570. height of the image.  You query but not not change the size of the
  1571. image once it's created.
  1572.  
  1573. =item B<$is_truecolor = $image-E<gt>isTrueColor()>
  1574.  
  1575. This method will return a boolean representing whether the image
  1576. is true color or not.
  1577.  
  1578. =item B<$flag = $image1-E<gt>compare($image2)>
  1579.  
  1580. Compare two images and return a bitmap describing the differenes
  1581. found, if any.  The return value must be logically ANDed with one or
  1582. more constants in order to determine the differences.  The following
  1583. constants are available:
  1584.  
  1585.   GD_CMP_IMAGE             The two images look different
  1586.   GD_CMP_NUM_COLORS        The two images have different numbers of colors
  1587.   GD_CMP_COLOR             The two images' palettes differ
  1588.   GD_CMP_SIZE_X            The two images differ in the horizontal dimension
  1589.   GD_CMP_SIZE_Y            The two images differ in the vertical dimension
  1590.   GD_CMP_TRANSPARENT       The two images have different transparency
  1591.   GD_CMP_BACKGROUND        The two images have different background colors
  1592.   GD_CMP_INTERLACE         The two images differ in their interlace
  1593.   GD_CMP_TRUECOLOR         The two images are not both true color
  1594.  
  1595. The most important of these is GD_CMP_IMAGE, which will tell you
  1596. whether the two images will look different, ignoring differences in the
  1597. order of colors in the color palette and other invisible changes.  The
  1598. constants are not imported by default, but must be imported individually
  1599. or by importing the :cmp tag.  Example:
  1600.  
  1601.   use GD qw(:DEFAULT :cmp);
  1602.   # get $image1 from somewhere
  1603.   # get $image2 from somewhere
  1604.   if ($image1->compare($image2) & GD_CMP_IMAGE) {
  1605.      warn "images differ!";
  1606.   }
  1607.  
  1608. =item B<$image-E<gt>clip($x1,$y1,$x2,$y2)>
  1609.  
  1610. =item B<($x1,$y1,$x2,$y2) = $image-E<gt>clip>
  1611.  
  1612. Set or get the clipping rectangle.  When the clipping rectangle is
  1613. set, all drawing will be clipped to occur within this rectangle.  The
  1614. clipping rectangle is initially set to be equal to the boundaries of
  1615. the whole image. Change it by calling clip() with the coordinates of
  1616. the new clipping rectangle.  Calling clip() without any arguments will
  1617. return the current clipping rectangle.
  1618.  
  1619. =item B<$flag = $image-E<gt>boundsSafe($x,$y)>
  1620.  
  1621. The boundsSafe() method will return true if the point indicated by
  1622. ($x,$y) is within the clipping rectangle, or false if it is not.  If
  1623. the clipping rectangle has not been set, then it will return true if
  1624. the point lies within the image boundaries.
  1625.  
  1626. =back
  1627.  
  1628. =head1 Polygons
  1629.  
  1630. A few primitive polygon creation and manipulation methods are
  1631. provided.  They aren't part of the Gd library, but I thought they
  1632. might be handy to have around (they're borrowed from my qd.pl
  1633. Quickdraw library).  Also see L<GD::Polyline>.
  1634.  
  1635. =over 3
  1636.  
  1637. =item B<$poly = GD::Polygon-E<gt>new>
  1638.  
  1639. Create an empty polygon with no vertices.
  1640.  
  1641.     $poly = new GD::Polygon;
  1642.  
  1643. =item B<$poly-E<gt>addPt($x,$y)>
  1644.  
  1645. Add point (x,y) to the polygon.
  1646.  
  1647.     $poly->addPt(0,0);
  1648.     $poly->addPt(0,50);
  1649.     $poly->addPt(25,25);
  1650.     $myImage->fillPoly($poly,$blue);
  1651.  
  1652. =item B<($x,$y) = $poly-E<gt>getPt($index)>
  1653.  
  1654. Retrieve the point at the specified vertex.
  1655.  
  1656.     ($x,$y) = $poly->getPt(2);
  1657.  
  1658. =item B<$poly-E<gt>setPt($index,$x,$y)>
  1659.  
  1660. Change the value of an already existing vertex.  It is an error to set
  1661. a vertex that isn't already defined.
  1662.  
  1663.     $poly->setPt(2,100,100);
  1664.  
  1665. =item B<($x,$y) = $poly-E<gt>deletePt($index)>
  1666.  
  1667. Delete the specified vertex, returning its value.
  1668.  
  1669.     ($x,$y) = $poly->deletePt(1); 
  1670.  
  1671. =item B<$poly-E<gt>toPt($dx,$dy)>
  1672.  
  1673. Draw from current vertex to a new vertex, using relative (dx,dy)
  1674. coordinates.  If this is the first point, act like addPt().
  1675.  
  1676.     $poly->addPt(0,0);
  1677.     $poly->toPt(0,50);
  1678.     $poly->toPt(25,-25);
  1679.     $myImage->fillPoly($poly,$blue);
  1680.  
  1681. =item B<$vertex_count = $poly-E<gt>length>
  1682.  
  1683. Return the number of vertices in the polygon.
  1684.  
  1685.     $points = $poly->length;
  1686.  
  1687. =item B<@vertices = $poly-E<gt>vertices>
  1688.  
  1689. Return a list of all the verticies in the polygon object.  Each member
  1690. of the list is a reference to an (x,y) array.
  1691.  
  1692.     @vertices = $poly->vertices;
  1693.     foreach $v (@vertices)
  1694.        print join(",",@$v),"\n";
  1695.     }
  1696.  
  1697. =item B<@rect = $poly-E<gt>bounds>
  1698.  
  1699. Return the smallest rectangle that completely encloses the polygon.
  1700. The return value is an array containing the (left,top,right,bottom) of
  1701. the rectangle.
  1702.  
  1703.     ($left,$top,$right,$bottom) = $poly->bounds;
  1704.  
  1705. =item B<$poly-E<gt>offset($dx,$dy)>
  1706.  
  1707. Offset all the vertices of the polygon by the specified horizontal
  1708. (dh) and vertical (dy) amounts.  Positive numbers move the polygon
  1709. down and to the right.
  1710.  
  1711.     $poly->offset(10,30);
  1712.  
  1713. =item B<$poly-E<gt>map($srcL,$srcT,$srcR,$srcB,$destL,$dstT,$dstR,$dstB)>
  1714.  
  1715. Map the polygon from a source rectangle to an equivalent position in a
  1716. destination rectangle, moving it and resizing it as necessary.  See
  1717. polys.pl for an example of how this works.  Both the source and
  1718. destination rectangles are given in (left,top,right,bottom)
  1719. coordinates.  For convenience, you can use the polygon's own bounding
  1720. box as the source rectangle.
  1721.  
  1722.     # Make the polygon really tall
  1723.     $poly->map($poly->bounds,0,0,50,200);
  1724.  
  1725. =item B<$poly-E<gt>scale($sx,$sy)>
  1726.  
  1727. Scale each vertex of the polygon by the X and Y factors indicated by
  1728. sx and sy.  For example scale(2,2) will make the polygon twice as
  1729. large.  For best results, move the center of the polygon to position
  1730. (0,0) before you scale, then move it back to its previous position.
  1731.  
  1732. =item B<$poly-E<gt>transform($sx,$rx,$sy,$ry,$tx,$ty)>
  1733.  
  1734. Run each vertex of the polygon through a transformation matrix, where
  1735. sx and sy are the X and Y scaling factors, rx and ry are the X and Y
  1736. rotation factors, and tx and ty are X and Y offsets.  See the Adobe
  1737. PostScript Reference, page 154 for a full explanation, or experiment.
  1738.  
  1739. =back
  1740.  
  1741. =head2 GD::Polyline
  1742.  
  1743. Please see L<GD::Polyline> for information on creating open polygons
  1744. and splines.
  1745.  
  1746. =head1 Font Utilities
  1747.  
  1748. The libgd library (used by the Perl GD library) has built-in support
  1749. for about half a dozen fonts, which were converted from public-domain
  1750. X Windows fonts.  For more fonts, compile libgd with TrueType support
  1751. and use the stringFT() call.
  1752.  
  1753. If you wish to add more built-in fonts, the directory bdf_scripts
  1754. contains two contributed utilities that may help you convert X-Windows
  1755. BDF-format fonts into the format that libgd uses internally.  However
  1756. these scripts were written for earlier versions of GD which included
  1757. its own mini-gd library.  These scripts will have to be adapted for
  1758. use with libgd, and the libgd library itself will have to be
  1759. recompiled and linked!  Please do not contact me for help with these
  1760. scripts: they are unsupported.
  1761.  
  1762. Each of these fonts is available both as an imported global
  1763. (e.g. B<gdSmallFont>) and as a package method
  1764. (e.g. B<GD::Font-E<gt>Small>).
  1765.  
  1766. =over 5
  1767.  
  1768. =item B<gdSmallFont>
  1769.  
  1770. =item B<GD::Font-E<gt>Small>
  1771.  
  1772. This is the basic small font, "borrowed" from a well known public
  1773. domain 6x12 font.
  1774.  
  1775. =item B<gdLargeFont>
  1776.  
  1777. =item B<GD::Font-E<gt>Large>
  1778.  
  1779. This is the basic large font, "borrowed" from a well known public
  1780. domain 8x16 font.
  1781.  
  1782. =item B<gdMediumBoldFont>
  1783.  
  1784. =item B<GD::Font-E<gt>MediumBold>
  1785.  
  1786. This is a bold font intermediate in size between the small and large
  1787. fonts, borrowed from a public domain 7x13 font;
  1788.  
  1789. =item B<gdTinyFont>
  1790.  
  1791. =item B<GD::Font-E<gt>Tiny>
  1792.  
  1793. This is a tiny, almost unreadable font, 5x8 pixels wide.
  1794.  
  1795. =item B<gdGiantFont>
  1796.  
  1797. =item B<GD::Font-E<gt>Giant>
  1798.  
  1799. This is a 9x15 bold font converted by Jan Pazdziora from a sans serif
  1800. X11 font.
  1801.  
  1802. =item B<$font-E<gt>nchars>
  1803.  
  1804. This returns the number of characters in the font.
  1805.  
  1806.     print "The large font contains ",gdLargeFont->nchars," characters\n";
  1807.  
  1808. =item B<$font-E<gt>offset>
  1809.  
  1810. This returns the ASCII value of the first character in the font
  1811.  
  1812. =item B<$width = $font-E<gt>width>
  1813.  
  1814. =item B<$height = $font-E<gt>height>
  1815.  
  1816. =item C<height>
  1817.  
  1818. These return the width and height of the font.
  1819.  
  1820.   ($w,$h) = (gdLargeFont->width,gdLargeFont->height);
  1821.  
  1822. =back
  1823.  
  1824. =head1 Obtaining the C-language version of gd
  1825.  
  1826. libgd, the C-language version of gd, can be obtained at URL
  1827. http://www.boutell.com/gd/.  Directions for installing and using it
  1828. can be found at that site.  Please do not contact me for help with
  1829. libgd.
  1830.  
  1831. =head1 AUTHOR
  1832.  
  1833. The GD.pm interface is copyright 1995-2000, Lincoln D. Stein.  It is
  1834. distributed under the same terms as Perl itself.  See the "Artistic
  1835. License" in the Perl source code distribution for licensing terms.
  1836.  
  1837. The latest versions of GD.pm are available at
  1838.  
  1839.   http://stein.cshl.org/WWW/software/GD
  1840.  
  1841. =head1 SEE ALSO
  1842.  
  1843. L<GD::Polyline>,
  1844. L<Image::Magick>
  1845.  
  1846. =cut
  1847.