GD.3pm
上传用户:qdrechuli
上传日期:2022-08-01
资源大小:917k
文件大小:40k
- ." Automatically generated by Pod::Man version 1.15
- ." Tue Oct 8 11:46:50 2002
- ."
- ." Standard preamble:
- ." ======================================================================
- .de Sh " Subsection heading
- .br
- .if t .Sp
- .ne 5
- .PP
- fB\$1fR
- .PP
- ..
- .de Sp " Vertical space (when we can't use .PP)
- .if t .sp .5v
- .if n .sp
- ..
- .de Ip " List item
- .br
- .ie \n(.$>=3 .ne \$3
- .el .ne 3
- .IP "\$1" \$2
- ..
- .de Vb " Begin verbatim text
- .ft CW
- .nf
- .ne \$1
- ..
- .de Ve " End verbatim text
- .ft R
- .fi
- ..
- ." Set up some character translations and predefined strings. *(-- will
- ." give an unbreakable dash, *(PI will give pi, *(L" will give a left
- ." double quote, and *(R" will give a right double quote. | will give a
- ." real vertical bar. *(C+ will give a nicer C++. Capital omega is used
- ." to do unbreakable dashes and therefore won't be available. *(C` and
- ." *(C' expand to `' in nroff, nothing in troff, for use with C<>
- .tr (*W-|(bv*(Tr
- .ds C+ Cv'-.1v'h'-1p's-2+h'-1p'+s0v'.1v'h'-1p'
- .ie n {
- . ds -- (*W-
- . ds PI pi
- . if (n(.H=4u)&(1m=24u) .ds -- (*Wh'-12u'(*Wh'-12u'-" diablo 10 pitch
- . if (n(.H=4u)&(1m=20u) .ds -- (*Wh'-12u'(*Wh'-8u'-" diablo 12 pitch
- . ds L" ""
- . ds R" ""
- . ds C` ""
- . ds C' ""
- 'br}
- .el{
- . ds -- |(em|
- . ds PI (*p
- . ds L" ``
- . ds R" ''
- 'br}
- ."
- ." If the F register is turned on, we'll generate index entries on stderr
- ." for titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and
- ." index entries marked with X<> in POD. Of course, you'll have to process
- ." the output yourself in some meaningful fashion.
- .if nF {
- . de IX
- . tm Index:\$1t\n%t"\$2"
- ..
- . nr % 0
- . rr F
- .}
- ."
- ." For nroff, turn off justification. Always turn off hyphenation; it
- ." makes way too many mistakes in technical documents.
- .hy 0
- .if n .na
- ."
- ." Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
- ." Fear. Run. Save yourself. No user-serviceable parts.
- .bd B 3
- . " fudge factors for nroff and troff
- .if n {
- . ds #H 0
- . ds #V .8m
- . ds #F .3m
- . ds #[ f1
- . ds #] fP
- .}
- .if t {
- . ds #H ((1u-(\\n(.fu%2u))*.13m)
- . ds #V .6m
- . ds #F 0
- . ds #[ &
- . ds #] &
- .}
- . " simple accents for nroff and troff
- .if n {
- . ds ' &
- . ds ` &
- . ds ^ &
- . ds , &
- . ds ~ ~
- . ds /
- .}
- .if t {
- . ds ' \k:h'-(\n(.wu*8/10-*(#H)''h"|\n:u"
- . ds ` \k:h'-(\n(.wu*8/10-*(#H)'`h'|\n:u'
- . ds ^ \k:h'-(\n(.wu*10/11-*(#H)'^h'|\n:u'
- . ds , \k:h'-(\n(.wu*8/10)',h'|\n:u'
- . ds ~ \k:h'-(\n(.wu-*(#H-.1m)'~h'|\n:u'
- . ds / \k:h'-(\n(.wu*8/10-*(#H)'z(slh'|\n:u'
- .}
- . " troff and (daisy-wheel) nroff accents
- .ds : \k:h'-(\n(.wu*8/10-*(#H+.1m+*(#F)'v'-*(#V'z.h'.2m+*(#F'.h'|\n:u'v'*(#V'
- .ds 8 h'*(#H'(*bh'-*(#H'
- .ds o \k:h'-(\n(.wu+w'(de'u-*(#H)/2u'v'-.3n'*(#[z(dev'.3n'h'|\n:u'*(#]
- .ds d- h'*(#H'(pdh'-w'~'u'v'-.25m'f2(hyfPv'.25m'h'-*(#H'
- .ds D- D\k:h'-w'D'u'v'-.11m'z(hyv'.11m'h'|\n:u'
- .ds th *(#[v'.3m's+1Is-1v'-.3m'h'-(w'I'u*2/3)'s-1os+1*(#]
- .ds Th *(#[s+2Is-2h'-w'I'u*3/5'v'-.3m'ov'.3m'*(#]
- .ds ae ah'-(w'a'u*4/10)'e
- .ds Ae Ah'-(w'A'u*4/10)'E
- . " corrections for vroff
- .if v .ds ~ \k:h'-(\n(.wu*9/10-*(#H)'s-2u~ds+2h'|\n:u'
- .if v .ds ^ \k:h'-(\n(.wu*10/11-*(#H)'v'-.4m'^v'.4m'h'|\n:u'
- . " for low resolution devices (crt and lpr)
- .if n(.H>23 .if n(.V>19
- {
- . ds : e
- . ds 8 ss
- . ds o a
- . ds d- dh'-1'(ga
- . ds D- Dh'-1'(hy
- . ds th o'bp'
- . ds Th o'LP'
- . ds ae ae
- . ds Ae AE
- .}
- .rm #[ #] #H #V #F C
- ." ======================================================================
- ."
- .IX Title "GD 3"
- .TH GD 3 "perl v5.6.1" "1997-12-19" "User Contributed Perl Documentation"
- .UC
- .SH "NAME"
- &s-1GDs0.pm - Interface to Gd Graphics Library
- .SH "SYNOPSIS"
- .IX Header "SYNOPSIS"
- .Vb 1
- & use GD;
- .Ve
- .Vb 2
- & # create a new image
- & $im = new GD::Image(100,100);
- .Ve
- .Vb 5
- & # allocate some colors
- & $white = $im->colorAllocate(255,255,255);
- & $black = $im->colorAllocate(0,0,0);
- & $red = $im->colorAllocate(255,0,0);
- & $blue = $im->colorAllocate(0,0,255);
- .Ve
- .Vb 3
- & # make the background transparent and interlaced
- & $im->transparent($white);
- & $im->interlaced('true');
- .Ve
- .Vb 2
- & # Put a black frame around the picture
- & $im->rectangle(0,0,99,99,$black);
- .Ve
- .Vb 2
- & # Draw a blue oval
- & $im->arc(50,50,95,75,0,360,$blue);
- .Ve
- .Vb 2
- & # And fill it with red
- & $im->fill(50,50,$red);
- .Ve
- .Vb 2
- & # Convert the image to GIF and print it on standard output
- & print $im->gif;
- .Ve
- .SH "DESCRIPTION"
- .IX Header "DESCRIPTION"
- &fBs-1GDs0.pmfR is a port of Thomas Boutell's gd graphics library (see
- below). s-1GDs0 allows you to create color drawings using a large number of
- graphics primitives, and emit the drawings as s-1GIFs0 files.
- .PP
- &s-1GDs0 defines the following three classes:
- .if n .Ip "f(CW""""GD::Image""""fR" 5
- .el .Ip "f(CWGD::ImagefR" 5
- .IX Item "GD::Image"
- An image class, which holds the image data and accepts graphic
- primitive method calls.
- .if n .Ip "f(CW""""GD::Font""""fR" 5
- .el .Ip "f(CWGD::FontfR" 5
- .IX Item "GD::Font"
- A font class, which holds static font information and used for text
- rendering.
- .if n .Ip "f(CW""""GD::Polygon""""fR" 5
- .el .Ip "f(CWGD::PolygonfR" 5
- .IX Item "GD::Polygon"
- A simple polygon object, used for storing lists of vertices prior to
- rendering a polygon into an image.
- .PP
- A Simple Example:
- .PP
- .Vb 1
- & #!/usr/local/bin/perl
- .Ve
- .Vb 1
- & use GD;
- .Ve
- .Vb 2
- & # create a new image
- & $im = new GD::Image(100,100);
- .Ve
- .Vb 5
- & # allocate some colors
- & $white = $im->colorAllocate(255,255,255);
- & $black = $im->colorAllocate(0,0,0);
- & $red = $im->colorAllocate(255,0,0);
- & $blue = $im->colorAllocate(0,0,255);
- .Ve
- .Vb 3
- & # make the background transparent and interlaced
- & $im->transparent($white);
- & $im->interlaced('true');
- .Ve
- .Vb 2
- & # Put a black frame around the picture
- & $im->rectangle(0,0,99,99,$black);
- .Ve
- .Vb 2
- & # Draw a blue oval
- & $im->arc(50,50,95,75,0,360,$blue);
- .Ve
- .Vb 2
- & # And fill it with red
- & $im->fill(50,50,$red);
- .Ve
- .Vb 2
- & # Convert the image to GIF and print it on standard output
- & print $im->gif;
- .Ve
- Notes:
- .Ip "1. To create a new, empty image, send a fInew()fR message to s-1GD:s0:Image, passing it the width and height of the image you want to create. An image object will be returned. Other class methods allow you to initialize an image from a preexisting s-1GIFs0, s-1GDs0 or s-1XBMs0 file." 5
- .IX Item "1. To create a new, empty image, send a new() message to GD::Image, passing it the width and height of the image you want to create. An image object will be returned. Other class methods allow you to initialize an image from a preexisting GIF, GD or XBM file."
- .PD 0
- .Ip "2. Next you will ordinarily add colors to the image's color table. colors are added using a fIcolorAllocate()fR method call. The three parameters in each call are the red, green and blue (rgb) triples for the desired color. The method returns the index of that color in the image's color table. You should store these indexes for later use." 5
- .IX Item "2. Next you will ordinarily add colors to the image's color table. colors are added using a colorAllocate() method call. The three parameters in each call are the red, green and blue (rgb) triples for the desired color. The method returns the index of that color in the image's color table. You should store these indexes for later use."
- .Ip "3. Now you can do some drawing! The various graphics primitives are described below. In this example, we do some text drawing, create an oval, and create and draw a polygon." 5
- .IX Item "3. Now you can do some drawing! The various graphics primitives are described below. In this example, we do some text drawing, create an oval, and create and draw a polygon."
- .Ip "4. Polygons are created with a fInew()fR message to s-1GD:s0:Polygon. You can add points to the returned polygon one at a time using the fIaddPt()fR method. The polygon can then be passed to an image for rendering." 5
- .IX Item "4. Polygons are created with a new() message to GD::Polygon. You can add points to the returned polygon one at a time using the addPt() method. The polygon can then be passed to an image for rendering."
- .Ip "5. When you're done drawing, you can convert the image into s-1GIFs0 format by sending it a fIgif()fR message. It will return a (potentially large) scalar value containing the binary data for the image. Ordinarily you will print it out at this point or write it to a file." 5
- .IX Item "5. When you're done drawing, you can convert the image into GIF format by sending it a gif() message. It will return a (potentially large) scalar value containing the binary data for the image. Ordinarily you will print it out at this point or write it to a file."
- .PD
- .SH "Method Calls"
- .IX Header "Method Calls"
- .Sh "Creating and Saving Images"
- .IX Subsection "Creating and Saving Images"
- .if n .Ip "f(CW""""new""""fR" 5
- .el .Ip "f(CWnewfR" 5
- .IX Item "new"
- &f(CW*(C`GD::Image::new(width,height)*(C'fR fIclass methodfR
- .Sp
- To create a new, blank image, send a fInew()fR message to the s-1GD:s0:Image
- class. For example:
- .Sp
- .Vb 1
- & $myImage = new GD::Image(100,100) || die;
- .Ve
- This will create an image that is 100 x 100 pixels wide. If you don't
- specify the dimensions, a default of 64 x 64 will be chosen. If
- something goes wrong (e.g. insufficient memory), this call will
- return undef.
- .if n .Ip "f(CW""""newFromGif""""fR" 5
- .el .Ip "f(CWnewFromGiffR" 5
- .IX Item "newFromGif"
- &f(CW*(C`GD::Image::newFromGif(FILEHANDLE)*(C'fR fIclass methodfR
- .Sp
- This will create an image from a s-1GIFs0 file read in through the provided
- filehandle. The filehandle must previously have been opened on a
- valid s-1GIFs0 file or pipe. If successful, this call will return an
- initialized image which you can then manipulate as you please. If it
- fails, which usually happens if the thing at the other end of the
- filehandle is not a valid s-1GIFs0 file, the call returns undef. Notice
- that the call doesn't automatically close the filehandle for you.
- .Sp
- To get information about the size and color usage of the information,
- you can call the image query methods described below.
- .Sp
- .Vb 1
- & Example usage:
- .Ve
- .Vb 3
- & open (GIF,"barnswallow.gif") || die;
- & $myImage = newFromGif GD::Image(GIF) || die;
- & close GIF;
- .Ve
- .if n .Ip "f(CW""""newFromXbm""""fR" 5
- .el .Ip "f(CWnewFromXbmfR" 5
- .IX Item "newFromXbm"
- &f(CW*(C`GD::Image::newFromXbm(FILEHANDLE)*(C'fR fIclass methodfR
- .Sp
- This works in exactly the same way as f(CW*(C`newFromGif*(C'fR, but reads the
- contents of an X Bitmap file:
- .Sp
- .Vb 3
- & open (XBM,"coredump.xbm") || die;
- & $myImage = newFromXbm GD::Image(XBM) || die;
- & close XBM;
- .Ve
- .if n .Ip "f(CW""""newFromGd""""fR" 5
- .el .Ip "f(CWnewFromGdfR" 5
- .IX Item "newFromGd"
- &f(CW*(C`GD::Image::newFromGd(FILEHANDLE)*(C'fR fIclass methodfR
- .Sp
- This works in exactly the same way as f(CW*(C`newFromGif*(C'fR, but reads the
- contents of a s-1GDs0 file. s-1GDs0 is Tom Boutell's disk-based storage format,
- intended for the rare case when you need to read and write the image
- to disk quickly. It's not intended for regular use, because, unlike
- &s-1GIFs0 or s-1JPEGs0, no image compression is performed and these files can
- become fBs-1BIGs0fR.
- .Sp
- .Vb 3
- & open (GDF,"godzilla.gd") || die;
- & $myImage = newFromGd GD::Image(GDF) || die;
- & close GDF;
- .Ve
- .if n .Ip "f(CW""""gif""""fR" 5
- .el .Ip "f(CWgiffR" 5
- .IX Item "gif"
- &f(CW*(C`GD::Image::gif*(C'fR fIobject methodfR
- .Sp
- This returns the image data in s-1GIFs0 format. You can then print it,
- pipe it to a display program, or write it to a file. Example:
- .Sp
- .Vb 4
- & $gif_data = $myImage->gif;
- & open (DISPLAY,"| display -") || die;
- & print DISPLAY $gif_data;
- & close DISPLAY;
- .Ve
- .if n .Ip "f(CW""""gd""""fR" 5
- .el .Ip "f(CWgdfR" 5
- .IX Item "gd"
- &f(CW*(C`GD::Image::gd*(C'fR fIobject methodfR
- .Sp
- This returns the image data in s-1GDs0 format. You can then print it,
- pipe it to a display program, or write it to a file. Example:
- .Sp
- .Vb 1
- & print MYOUTFILE $myImage->gd;
- .Ve
- .Sh "Color Control"
- .IX Subsection "Color Control"
- .if n .Ip "f(CW""""colorAllocate""""fR" 5
- .el .Ip "f(CWcolorAllocatefR" 5
- .IX Item "colorAllocate"
- &f(CW*(C`GD::Image::colorAllocate(red,green,blue)*(C'fR fIobject methodfR
- .Sp
- This allocates a color with the specified red, green and blue
- components and returns its index in the color table, if specified.
- The first color allocated in this way becomes the image's background
- color. (255,255,255) is white (all pixels on). (0,0,0) is black (all
- pixels off). (255,0,0) is fully saturated red. (127,127,127) is 50%
- gray. You can find plenty of examples in /usr/X11/lib/X11/rgb.txt.
- .Sp
- If no colors are allocated, then this function returns -1.
- .Sp
- Example:
- .Sp
- .Vb 3
- & $white = $myImage->colorAllocate(0,0,0); #background color
- & $black = $myImage->colorAllocate(255,255,255);
- & $peachpuff = $myImage->colorAllocate(255,218,185);
- .Ve
- .if n .Ip "f(CW""""colorDeallocate""""fR" 5
- .el .Ip "f(CWcolorDeallocatefR" 5
- .IX Item "colorDeallocate"
- &f(CW*(C`GD::Image::colorDeallocate(colorIndex)*(C'fR fIobject methodfR
- .Sp
- This marks the color at the specified index as being ripe for
- reallocation. The next time colorAllocate is used, this entry will be
- replaced. You can call this method several times to deallocate
- multiple colors. There's no function result from this call.
- .Sp
- Example:
- .Sp
- .Vb 2
- & $myImage->colorDeallocate($peachpuff);
- & $peachy = $myImage->colorAllocate(255,210,185);
- .Ve
- .if n .Ip "f(CW""""colorClosest""""fR" 5
- .el .Ip "f(CWcolorClosestfR" 5
- .IX Item "colorClosest"
- &f(CW*(C`GD::Image::colorClosest(red,green,blue)*(C'fR fIobject methodfR
- .Sp
- This returns the index of the color closest in the color table to the
- red green and blue components specified. If no colors have yet been
- allocated, then this call returns -1.
- .Sp
- Example:
- .Sp
- .Vb 1
- & $apricot = $myImage->colorClosest(255,200,180);
- .Ve
- .if n .Ip "f(CW""""colorExact""""fR" 5
- .el .Ip "f(CWcolorExactfR" 5
- .IX Item "colorExact"
- &f(CW*(C`GD::Image::colorExact(red,green,blue)*(C'fR fIobject methodfR
- .Sp
- This returns the index of a color that exactly matches the specified
- red green and blue components. If such a color is not in the color
- table, this call returns -1.
- .Sp
- .Vb 2
- & $rosey = $myImage->colorExact(255,100,80);
- & warn "Everything's coming up roses.en" if $rosey >= 0;
- .Ve
- .if n .Ip "f(CW""""colorsTotal""""fR" 5
- .el .Ip "f(CWcolorsTotalfR" 5
- .IX Item "colorsTotal"
- &f(CW*(C`GD::Image::colorsTotal)*(C'fR fIobject methodfR
- .Sp
- This returns the total number of colors allocated in the object.
- .Sp
- .Vb 1
- & $maxColors = $myImage->colorsTotal;
- .Ve
- .if n .Ip "f(CW""""getPixel""""fR" 5
- .el .Ip "f(CWgetPixelfR" 5
- .IX Item "getPixel"
- &f(CW*(C`GD::Image::getPixel(x,y)*(C'fR fIobject methodfR
- .Sp
- This returns the color table index underneath the specified
- point. It can be combined with fIrgb()fR
- to obtain the rgb color underneath the pixel.
- .Sp
- Example:
- .Sp
- .Vb 2
- & $index = $myImage->getPixel(20,100);
- & ($r,$g,$b) = $myImage->rgb($index);
- .Ve
- .if n .Ip "f(CW""""rgb""""fR" 5
- .el .Ip "f(CWrgbfR" 5
- .IX Item "rgb"
- &f(CW*(C`GD::Image::rgb(colorIndex)*(C'fR fIobject methodfR
- .Sp
- This returns a list containing the red, green and blue components of
- the specified color index.
- .Sp
- Example:
- .Sp
- .Vb 1
- & @RGB = $myImage->rgb($peachy);
- .Ve
- .if n .Ip "f(CW""""transparent""""fR" 5
- .el .Ip "f(CWtransparentfR" 5
- .IX Item "transparent"
- &f(CW*(C`GD::Image::transparent(colorIndex)*(C'fR fIobject methodfR
- .Sp
- This marks the color at the specified index as being transparent.
- Portions of the image drawn in this color will be invisible. This is
- useful for creating paintbrushes of odd shapes, as well as for
- making s-1GIFs0 backgrounds transparent for displaying on the Web. Only
- one color can be transparent at any time. To disable transparency,
- specify -1 for the index.
- .Sp
- If you call this method without any parameters, it will return the
- current index of the transparent color, or -1 if none.
- .Sp
- Example:
- .Sp
- .Vb 5
- & open(GIF,"test.gif");
- & $im = newFromGif GD::Image(GIF);
- & $white = $im->colorClosest(255,255,255); # find white
- & $im->transparent($white);
- & print $im->gif;
- .Ve
- .Sh "Special Colors"
- .IX Subsection "Special Colors"
- &s-1GDs0 implements a number of special colors that can be used to achieve
- special effects. They are constants defined in the s-1GD::s0
- namespace, but automatically exported into your namespace when the s-1GDs0
- module is loaded.
- .if n .Ip "f(CW""""setBrush""""fR" 5
- .el .Ip "f(CWsetBrushfR" 5
- .IX Item "setBrush"
- .PD 0
- .if n .Ip "f(CW""""gdBrushed""""fR" 5
- .el .Ip "f(CWgdBrushedfR" 5
- .IX Item "gdBrushed"
- .PD
- &f(CW*(C`GD::Image::setBrush( )*(C'fR and f(CW*(C`GD::gdBrushed*(C'fR
- .Sp
- You can draw lines and shapes using a brush pattern. Brushes are
- just images that you can create and manipulate in the usual way. When
- you draw with them, their contents are used for the color and shape of
- the lines.
- .Sp
- To make a brushed line, you must create or load the brush first, then
- assign it to the image using f(CW*(C`setBrush*(C'fR. You can then draw in that
- with that brush using the f(CW*(C`gdBrushed*(C'fR special color. It's often
- useful to set the background of the brush to transparent so that
- the non-colored parts don't overwrite other parts of your image.
- .Sp
- Example:
- .Sp
- .Vb 6
- & # Create a brush at an angle
- & $diagonal_brush = new GD::Image(5,5);
- & $white = $diagonal_brush->allocateColor(255,255,255);
- & $black = $diagonal_brush->allocateColor(0,0,0);
- & $diagonal_brush->transparent($white);
- & $diagonal_brush->line(0,4,4,0,$black); # NE diagonal
- .Ve
- .Vb 2
- & # Set the brush
- & $myImage->setBrush($diagonal_brush);
- .Ve
- .Vb 2
- & # Draw a circle using the brush
- & $myImage->arc(50,50,25,25,0,360,gdBrushed);
- .Ve
- .if n .Ip "f(CW""""setStyle""""fR" 5
- .el .Ip "f(CWsetStylefR" 5
- .IX Item "setStyle"
- .PD 0
- .if n .Ip "f(CW""""gdStyled""""fR" 5
- .el .Ip "f(CWgdStyledfR" 5
- .IX Item "gdStyled"
- .PD
- &f(CW*(C`GD::Image::setStyle(@colors)*(C'fR and f(CW*(C`GD::gdStyled*(C'fR
- .Sp
- Styled lines consist of an arbitrary series of repeated colors and are
- useful for generating dotted and dashed lines. To create a styled
- line, use f(CW*(C`setStyle*(C'fR to specify a repeating series of colors. It
- accepts an array consisting of one or more color indexes. Then
- draw using the f(CW*(C`gdStyled*(C'fR special color. Another special color,
- &f(CW*(C`gdTransparent*(C'fR can be used to introduce holes in the line, as the
- example shows.
- .Sp
- Example:
- .Sp
- .Vb 6
- & # Set a style consisting of 4 pixels of yellow,
- & # 4 pixels of blue, and a 2 pixel gap
- & $myImage->setStyle($yellow,$yellow,$yellow,$yellow,
- & $blue,$blue,$blue,$blue,
- & gdTransparent,gdTransparent);
- & $myImage->arc(50,50,25,25,0,360,gdStyled);
- .Ve
- To combine the f(CW*(C`gdStyled*(C'fR and f(CW*(C`gdBrushed*(C'fR behaviors, you can specify
- &f(CW*(C`gdStyledBrushed*(C'fR. In this case, a pixel from the current brush
- pattern is rendered wherever the color specified in fIsetStyle()fR is
- neither gdTransparent nor 0.
- .if n .Ip "f(CW""""gdTiled""""fR" 5
- .el .Ip "f(CWgdTiledfR" 5
- .IX Item "gdTiled"
- Draw filled shapes and flood fills using a pattern. The pattern is
- just another image. The image will be tiled multiple times in order
- to fill the required space, creating wallpaper effects. You must call
- &f(CW*(C`setTile*(C'fR in order to define the particular tile pattern you'll use
- for drawing when you specify the gdTiled color.
- details.
- .if n .Ip "f(CW""""gdStyled""""fR" 5
- .el .Ip "f(CWgdStyledfR" 5
- .IX Item "gdStyled"
- The gdStyled color is used for creating dashed and dotted lines. A
- styled line can contain any series of colors and is created using the
- &f(CW*(C`setStyled*(C'fR command.
- .Sh "Drawing Commands"
- .IX Subsection "Drawing Commands"
- .if n .Ip "f(CW""""setPixel""""fR" 5
- .el .Ip "f(CWsetPixelfR" 5
- .IX Item "setPixel"
- &f(CW*(C`GD::Image::setPixel(x,y,color)*(C'fR fIobject methodfR
- .Sp
- This sets the pixel at (x,y) to the specified color index. No value
- is returned from this method. The coordinate system starts at the
- upper left at (0,0) and gets larger as you go down and to the right.
- You can use a real color, or one of the special colors gdBrushed,
- gdStyled and gdStyledBrushed can be specified.
- .Sp
- Example:
- .Sp
- .Vb 2
- & # This assumes $peach already allocated
- & $myImage->setPixel(50,50,$peach);
- .Ve
- .if n .Ip "f(CW""""line""""fR" 5
- .el .Ip "f(CWlinefR" 5
- .IX Item "line"
- &f(CW*(C`GD::Image::line(x1,y1,x2,y2,color)*(C'fR fIobject methodfR
- .Sp
- This draws a line from (x1,y1) to (x2,y2) of the specified color. You
- can use a real color, or one of the special colors gdBrushed,
- gdStyled and gdStyledBrushed.
- .Sp
- Example:
- .Sp
- .Vb 3
- & # Draw a diagonal line using the currently defind
- & # paintbrush pattern.
- & $myImage->line(0,0,150,150,gdBrushed);
- .Ve
- .if n .Ip "f(CW""""dashedLine""""fR" 5
- .el .Ip "f(CWdashedLinefR" 5
- .IX Item "dashedLine"
- &f(CW*(C`GD::Image::dashedLine(x1,y1,x2,y2,color)*(C'fR fIobject methodfR
- .Sp
- This draws a dashed line from (x1,y1) to (x2,y2) in the specified
- color. A more powerful way to generate arbitrary dashed and dotted
- lines is to use the fIsetStyle()fR method described below and to draw with
- the special color gdStyled.
- .Sp
- Example:
- .Sp
- .Vb 1
- & $myImage->dashedLine(0,0,150,150,$blue);
- .Ve
- .if n .Ip "f(CW""""rectangle""""fR" 5
- .el .Ip "f(CWrectanglefR" 5
- .IX Item "rectangle"
- &f(CW*(C`GD::Image::rectangle(x1,y1,x2,y2,color)*(C'fR fIobject methodfR
- .Sp
- This draws a rectangle with the specified color. (x1,y1) and (x2,y2)
- are the upper left and lower right corners respectively. Both real
- color indexes and the special colors gdBrushed, gdStyled and
- gdStyledBrushed are accepted.
- .Sp
- Example:
- .Sp
- .Vb 1
- & $myImage->rectangle(10,10,100,100,$rose);
- .Ve
- .if n .Ip "f(CW""""filledRectangle""""fR" 5
- .el .Ip "f(CWfilledRectanglefR" 5
- .IX Item "filledRectangle"
- &f(CW*(C`GD::Image::filledRectangle(x1,y1,x2,y2,color)*(C'fR fIobject methodfR
- .Sp
- This draws a rectangle filed with the specified color. You can use a
- real color, or the special fill color gdTiled to fill the polygon
- with a pattern.
- .Sp
- Example:
- .Sp
- .Vb 4
- & # read in a fill pattern and set it
- & open(GIF,"happyface.gif") || die;
- & $tile = newFromGif GD::Image(GIF);
- & $myImage->setTile($tile);
- .Ve
- .Vb 2
- & # draw the rectangle, filling it with the pattern
- & $myImage->filledRectangle(10,10,150,200,gdTiled);
- .Ve
- .if n .Ip "f(CW""""polygon""""fR" 5
- .el .Ip "f(CWpolygonfR" 5
- .IX Item "polygon"
- &f(CW*(C`GD::Image::polygon(polygon,color)*(C'fR fIobject methodfR
- .Sp
- This draws a polygon with the specified color. The polygon must be
- created first (see below). The polygon must have at least three
- vertices. If the last vertex doesn't close the polygon, the method
- will close it for you. Both real color indexes and the special
- colors gdBrushed, gdStyled and gdStyledBrushed can be specified.
- .Sp
- Example:
- .Sp
- .Vb 5
- & $poly = new GD::Polygon;
- & $poly->addPt(50,0);
- & $poly->addPt(99,99);
- & $poly->addPt(0,99);
- & $myImage->polygon($poly,$blue);
- .Ve
- .if n .Ip "f(CW""""filledPolygon""""fR" 5
- .el .Ip "f(CWfilledPolygonfR" 5
- .IX Item "filledPolygon"
- &f(CW*(C`GD::Image::filledPolygon(poly,color)*(C'fR fIobject methodfR
- .Sp
- This draws a polygon filled with the specified color. You can use a
- real color, or the special fill color gdTiled to fill the polygon
- with a pattern.
- .Sp
- Example:
- .Sp
- .Vb 5
- & # make a polygon
- & $poly = new GD::Polygon;
- & $poly->addPt(50,0);
- & $poly->addPt(99,99);
- & $poly->addPt(0,99);
- .Ve
- .Vb 2
- & # draw the polygon, filling it with a color
- & $myImage->filledPolygon($poly,$peachpuff);
- .Ve
- .if n .Ip "f(CW""""arc""""fR" 5
- .el .Ip "f(CWarcfR" 5
- .IX Item "arc"
- &f(CW*(C`GD::Image::arc(cx,cy,width,height,start,end,color)*(C'fR fIobject methodfR
- .Sp
- This draws arcs and ellipses. (cx,cy) are the center of the arc, and
- (width,height) specify the width and height, respectively. The
- portion of the ellipse covered by the arc are controlled by start and
- end, both of which are given in degrees from 0 to 360. Zero is at the
- top of the ellipse, and angles increase clockwise. To specify a
- complete ellipse, use 0 and 360 as the starting and ending angles. To
- draw a circle, use the same value for width and height.
- .Sp
- You can specify a normal color or one of the special colors gdBrushed,
- gdStyled, or gdStyledBrushed.
- .Sp
- Example:
- .Sp
- .Vb 2
- & # draw a semicircle centered at 100,100
- & $myImage->arc(100,100,50,50,0,180,$blue);
- .Ve
- .if n .Ip "f(CW""""fill""""fR" 5
- .el .Ip "f(CWfillfR" 5
- .IX Item "fill"
- &f(CW*(C`GD::Image::fill(x,y,color)*(C'fR fIobject methodfR
- .Sp
- This method flood-fills regions with the specified color. The color
- will spread through the image, starting at point (x,y), until it is
- stopped by a pixel of a different color from the starting pixel (this
- is similar to the *(L"paintbucket*(R" in many popular drawing toys). You
- can specify a normal color, or the special color gdTiled, to flood-fill
- with patterns.
- .Sp
- Example:
- .Sp
- .Vb 3
- & # Draw a rectangle, and then make its interior blue
- & $myImage->rectangle(10,10,100,100,$black);
- & $myImage->fill(50,50,$blue);
- .Ve
- .if n .Ip "f(CW""""GD::Image::fillToBorder(x,y,bordercolor,color)""""fR fIobject methodfR" 5
- .el .Ip "f(CWGD::Image::fillToBorder(x,y,bordercolor,color)fR fIobject methodfR" 5
- .IX Item "GD::Image::fillToBorder(x,y,bordercolor,color) object method"
- Like f(CW*(C`fill*(C'fR, this method flood-fills regions with the specified color,
- starting at position (x,y).
- However, instead of stopping when it hits a pixel of a different color
- than the starting pixel, flooding will only stop when it hits the
- color specified by bordercolor. You must specify a normal indexed
- color for the bordercolor. However, you are free to use the gdTiled
- color for the fill.
- .Sp
- Example:
- .Sp
- .Vb 3
- & # This has the same effect as the previous example
- & $myImage->rectangle(10,10,100,100,$black);
- & $myImage->fillToBorder(50,50,$black,$blue);
- .Ve
- .Sh "Image Copying Commands"
- .IX Subsection "Image Copying Commands"
- Two methods are provided for copying a rectangular region from one
- image to another. One method copies a region without resizing it.
- The other allows you to stretch the region during the copy operation.
- .PP
- With either of these methods it is important to know that the routines
- will attempt to flesh out the destination image's color table to match
- the colors that are being copied from the source. If the
- destination's color table is already full, then the routines will
- attempt to find the best match, with varying results.
- .if n .Ip "f(CW""""copy""""fR" 5
- .el .Ip "f(CWcopyfR" 5
- .IX Item "copy"
- &f(CW*(C`GD::Image::copy(sourceImage,dstX,dstY,srcX,srcY,width,height)*(C'fR fIobject methodfR
- .Sp
- This is the simpler of the two copy operations, copying the specified
- region from the source image to the destination image (the one
- performing the method call). (srcX,srcY) specify the upper left
- corner of a rectangle in the source image, and (width,height) give the
- width and height of the region to copy. (dstX,dstY) control where in
- the destination image to stamp the copy. You can use the same image
- for both the source and the destination, but the source and
- destination regions must not overlap or strange things will happen.
- .Sp
- Example:
- .Sp
- .Vb 7
- & $myImage = new GD::Image(100,100);
- & ... various drawing stuff ...
- & $srcImage = new GD::Image(50,50);
- & ... more drawing stuff ...
- & # copy a 25x25 pixel region from $srcImage to
- & # the rectangle starting at (10,10) in $myImage
- & $myImage->copy($srcImage,10,10,0,0,25,25);
- .Ve
- .if n .Ip "f(CW""""copyResized""""fR" 5
- .el .Ip "f(CWcopyResizedfR" 5
- .IX Item "copyResized"
- &f(CW*(C`GD::Image::copyResized(sourceImage,dstX,dstY,srcX,srcY,destW,destH,srcW,srcH)*(C'fR fIobject methodfR
- .Sp
- This method is similar to fIcopy()fR but allows you to choose different
- sizes for the source and destination rectangles. The source and
- destination rectangle's are specified independently by (srcW,srcH) and
- (destW,destH) respectively. fIcopyResized()fR will stretch or shrink the
- image to accomodate the size requirements.
- .Sp
- Example:
- .Sp
- .Vb 7
- & $myImage = new GD::Image(100,100);
- & ... various drawing stuff ...
- & $srcImage = new GD::Image(50,50);
- & ... more drawing stuff ...
- & # copy a 25x25 pixel region from $srcImage to
- & # a larger rectangle starting at (10,10) in $myImage
- & $myImage->copyResized($srcImage,10,10,0,0,50,50,25,25);
- .Ve
- .Sh "Character and String Drawing"
- .IX Subsection "Character and String Drawing"
- Gd allows you to draw characters and strings, either in normal
- horizontal orientation or rotated 90 degrees. These routines use a
- &s-1GD:s0:Font object, described in more detail below. There are four
- built-in fonts, available in global variables gdLargeFont,
- gdMediumBoldFont, gdSmallFont and gdTinyFont. Currently there is no
- way of dynamically creating your own fonts.
- .if n .Ip "f(CW""""string""""fR" 5
- .el .Ip "f(CWstringfR" 5
- .IX Item "string"
- &f(CW*(C`GD::Image::string(font,x,y,string,color)*(C'fR fIObject MethodfR
- .Sp
- This method draws a string startin at position (x,y) in the specified
- font and color. Your choices of fonts are gdSmallFont, gdMediumBoldFont,
- gdTinyFont and gdLargeFont.
- .Sp
- Example:
- .Sp
- .Vb 1
- & $myImage->string(gdSmallFont,2,10,"Peachy Keen",$peach);
- .Ve
- .if n .Ip "f(CW""""stringUp""""fR" 5
- .el .Ip "f(CWstringUpfR" 5
- .IX Item "stringUp"
- &f(CW*(C`GD::Image::stringUp(font,x,y,string,color)*(C'fR fIObject MethodfR
- .Sp
- Just like the previous call, but draws the text rotated
- counterclockwise 90 degrees.
- .if n .Ip "f(CW""""char""""fR" 5
- .el .Ip "f(CWcharfR" 5
- .IX Item "char"
- .PD 0
- .if n .Ip "f(CW""""charUp""""fR" 5
- .el .Ip "f(CWcharUpfR" 5
- .IX Item "charUp"
- .PD
- &f(CW*(C`GD::Image::char(font,x,y,char,color)*(C'fR fIObject MethodfR
- &f(CW*(C`GD::Image::charUp(font,x,y,char,color)*(C'fR fIObject MethodfR
- .Sp
- These methods draw single characters at position (x,y) in the
- specified font and color. They're carry-overs from the C interface,
- where there is a distinction between characters and strings. Perl is
- insensible to such subtle distinctions.
- .Sh "Miscellaneous Image Methods"
- .IX Subsection "Miscellaneous Image Methods"
- .if n .Ip "f(CW""""interlaced""""fR" 5
- .el .Ip "f(CWinterlacedfR" 5
- .IX Item "interlaced"
- &f(CW*(C`GD::Image::interlaced( )*(C'fR f(CW*(C`GD::Image::interlaced(1)*(C'fR fIObject methodfR
- .Sp
- This method sets or queries the image's interlaced setting. Interlace
- produces a cool venetian blinds effect on certain viewers. Provide a
- true parameter to set the interlace attribute. Provide undef to
- disable it. Call the method without parameters to find out the
- current setting.
- .Ip "c<getBounds>" 5
- .IX Item "c<getBounds>"
- &f(CW*(C`GD::Image::getBounds( )*(C'fR fIObject methodfR
- .Sp
- This method will return a two-member list containing the width and
- height of the image. You query but not not change the size of the
- image once it's created.
- .Sh "Polygon Methods"
- .IX Subsection "Polygon Methods"
- A few primitive polygon creation and manipulation methods are
- provided. They aren't part of the Gd library, but I thought they
- might be handy to have around (they're borrowed from my qd.pl
- Quickdraw library).
- .Ip "c<new>" 5
- .IX Item "c<new>"
- &f(CW*(C`GD::Polygon::new*(C'fR fIclass methodfR
- .Sp
- Create an empty polygon with no vertices.
- .Sp
- .Vb 1
- & $poly = new GD::Polygon;
- .Ve
- .if n .Ip "f(CW""""addPt""""fR" 5
- .el .Ip "f(CWaddPtfR" 5
- .IX Item "addPt"
- &f(CW*(C`GD::Polygon::addPt(x,y)*(C'fR fIobject methodfR
- .Sp
- Add point (x,y) to the polygon.
- .Sp
- .Vb 4
- & $poly->addPt(0,0);
- & $poly->addPt(0,50);
- & $poly->addPt(25,25);
- & $myImage->fillPoly($poly,$blue);
- .Ve
- .if n .Ip "f(CW""""getPt""""fR" 5
- .el .Ip "f(CWgetPtfR" 5
- .IX Item "getPt"
- &f(CW*(C`GD::Polygon::getPt(index)*(C'fR fIobject methodfR
- .Sp
- Retrieve the point at the specified vertex.
- .Sp
- .Vb 1
- & ($x,$y) = $poly->getPt(2);
- .Ve
- .if n .Ip "f(CW""""setPt""""fR" 5
- .el .Ip "f(CWsetPtfR" 5
- .IX Item "setPt"
- &f(CW*(C`GD::Polygon::setPt(index,x,y)*(C'fR fIobject methodfR
- .Sp
- Change the value of an already existing vertex. It is an error to set
- a vertex that isn't already defined.
- .Sp
- .Vb 1
- & $poly->setPt(2,100,100);
- .Ve
- .if n .Ip "f(CW""""deletePt""""fR" 5
- .el .Ip "f(CWdeletePtfR" 5
- .IX Item "deletePt"
- &f(CW*(C`GD::Polygon:deletePt(index)*(C'fR fIobject methodfR
- .Sp
- Delete the specified vertex, returning its value.
- .Sp
- .Vb 1
- & ($x,$y) = $poly->deletePt(1);
- .Ve
- .if n .Ip "f(CW""""toPt""""fR" 5
- .el .Ip "f(CWtoPtfR" 5
- .IX Item "toPt"
- &f(CW*(C`GD::Polygon::toPt(dx,dy)*(C'fR fIobject methodfR
- .Sp
- Draw from current vertex to a new vertex, using relative
- (dx,dy) coordinates. If this is the first point, act like
- &fIaddPt()fR.
- .Sp
- .Vb 4
- & $poly->addPt(0,0);
- & $poly->toPt(0,50);
- & $poly->toPt(25,-25);
- & $myImage->fillPoly($poly,$blue);
- .Ve
- .if n .Ip "f(CW""""length""""fR" 5
- .el .Ip "f(CWlengthfR" 5
- .IX Item "length"
- &f(CW*(C`GD::Polygon::length*(C'fR fIobject methodfR
- .Sp
- Return the number of vertices in the polygon.
- .Sp
- .Vb 1
- & $points = $poly->length;
- .Ve
- .if n .Ip "f(CW""""vertices""""fR" 5
- .el .Ip "f(CWverticesfR" 5
- .IX Item "vertices"
- &f(CW*(C`GD::Polygon::vertices*(C'fR fIobject methodfR
- .Sp
- Return a list of all the verticies in the polygon object. Each
- membver of the list is a reference to an (x,y) array.
- .Sp
- .Vb 4
- & @vertices = $poly->vertices;
- & foreach $v (@vertices)
- & print join(",",@$v),"en";
- & }
- .Ve
- .if n .Ip "f(CW""""bounds""""fR" 5
- .el .Ip "f(CWboundsfR" 5
- .IX Item "bounds"
- &f(CW*(C`GD::Polygon::bounds*(C'fR fIobject methodfR
- .Sp
- Return the smallest rectangle that completely encloses the polygon.
- The return value is an array containing the (left,top,right,bottom) of
- the rectangle.
- .Sp
- .Vb 1
- & ($left,$top,$right,$bottom) = $poly->bounds;
- .Ve
- .if n .Ip "f(CW""""offset""""fR" 5
- .el .Ip "f(CWoffsetfR" 5
- .IX Item "offset"
- &f(CW*(C`GD::Polygon::offset(dx,dy)*(C'fR fIobject methodfR
- .Sp
- Offset all the vertices of the polygon by the specified horizontal
- (dh) and vertical (dy) amounts. Positive numbers move the polygon
- down and to the right.
- .Sp
- .Vb 1
- & $poly->offset(10,30);
- .Ve
- .if n .Ip "f(CW""""map""""fR" 5
- .el .Ip "f(CWmapfR" 5
- .IX Item "map"
- &f(CW*(C`GD::Polygon::map(srcL,srcT,srcR,srcB,destL,dstT,dstR,dstB)*(C'fR fIobject methodfR
- .Sp
- Map the polygon from a source rectangle to an equivalent position in a
- destination rectangle, moving it and resizing it as necessary. See
- polys.pl for an example of how this works. Both the source and
- destination rectangles are given in (left,top,right,bottom)
- coordinates. For convenience, you can use the polygon's own bounding
- box as the source rectangle.
- .Sp
- .Vb 2
- & # Make the polygon really tall
- & $poly->map($poly->bounds,0,0,50,200);
- .Ve
- .if n .Ip "f(CW""""scale""""fR" 5
- .el .Ip "f(CWscalefR" 5
- .IX Item "scale"
- &f(CW*(C`GD::Polygon::scale(sx,sy)*(C'fR fIobject methodfR
- .Sp
- Scale each vertex of the polygon by the X and Y factors indicated by
- sx and sy. For example scale(2,2) will make the polygon twice as
- large. For best results, move the center of the polygon to position
- (0,0) before you scale, then move it back to its previous position.
- .if n .Ip "f(CW""""transform""""fR" 5
- .el .Ip "f(CWtransformfR" 5
- .IX Item "transform"
- &f(CW*(C`GD::Polygon::transform(sx,rx,sy,ry,tx,ty)*(C'fR fIobject methodfR
- .Sp
- Run each vertex of the polygon through a transformation matrix, where
- sx and sy are the X and Y scaling factors, rx and ry are the X and Y
- rotation factors, and tx and ty are X and Y offsets. See the Adobe
- PostScript Reference, page 154 for a full explanation, or experiment.
- .Sh "Font Utilities"
- .IX Subsection "Font Utilities"
- Gd's support for fonts is minimal. Basically you have access to
- gdSmallFont and gdLargeFont for drawing, and not much else. However,
- for future compatibility, I've made the fonts into perl objects of
- type s-1GD:s0:Font that you can query and, perhaps someday manipulate.
- .if n .Ip "f(CW""""gdSmallFont""""fR" 5
- .el .Ip "f(CWgdSmallFontfR" 5
- .IX Item "gdSmallFont"
- &f(CW*(C`GD::Font::gdSmallFont*(C'fR fIconstantfR
- .Sp
- This is the basic small font, *(L"borrowed*(R" from a well known public
- domain 6x12 font.
- .if n .Ip "f(CW""""gdLargeFont""""fR" 5
- .el .Ip "f(CWgdLargeFontfR" 5
- .IX Item "gdLargeFont"
- &f(CW*(C`GD::Font::gdLargeFont*(C'fR fIconstantfR
- .Sp
- This is the basic large font, *(L"borrowed*(R" from a well known public
- domain 8x16 font.
- .if n .Ip "f(CW""""gdMediumBoldFont""""fR" 5
- .el .Ip "f(CWgdMediumBoldFontfR" 5
- .IX Item "gdMediumBoldFont"
- &f(CW*(C`GD::Font::gdMediumBoldFont*(C'fR fIconstantfR
- .Sp
- This is a bold font intermediate in size between the small and large
- fonts, borrowed from a public domain 7x13 font;
- .if n .Ip "f(CW""""gdTinyFont""""fR" 5
- .el .Ip "f(CWgdTinyFontfR" 5
- .IX Item "gdTinyFont"
- &f(CW*(C`GD::Font::gdTinyFont*(C'fR fIconstantfR
- .Sp
- This is a tiny, almost unreadable font, 5x8 pixels wide.
- .if n .Ip "f(CW""""nchars""""fR" 5
- .el .Ip "f(CWncharsfR" 5
- .IX Item "nchars"
- &f(CW*(C`GD::Font::nchars*(C'fR fIobject methodfR
- .Sp
- This returns the number of characters in the font.
- .Sp
- .Vb 1
- & print "The large font contains ",gdLargeFont->nchars," charactersen";
- .Ve
- .if n .Ip "f(CW""""offset""""fR" 5
- .el .Ip "f(CWoffsetfR" 5
- .IX Item "offset"
- &f(CW*(C`GD::Font::offset*(C'fR fIobject methodfR
- .Sp
- This returns the s-1ASCIIs0 value of the first character in the font
- .if n .Ip "f(CW""""width""""fR" 5
- .el .Ip "f(CWwidthfR" 5
- .IX Item "width"
- .PD 0
- .if n .Ip "f(CW""""height""""fR" 5
- .el .Ip "f(CWheightfR" 5
- .IX Item "height"
- .PD
- &f(CW*(C`GD::Font::width*(C'fR f(CW*(C`GD::Font::height*(C'fR fIobject methodsfR
- .Sp
- These return the width and height of the font.
- .Sp
- .Vb 1
- & ($w,$h) = (gdLargeFont->width,gdLargeFont->height);
- .Ve
- .SH "Obtaining the C-language version of gd"
- .IX Header "Obtaining the C-language version of gd"
- libgd, the C-language version of gd, can be obtained at s-1URLs0
- http://www.boutell.com/gd/gd.html. Directions for installing and
- using it can be found at that site. Please do not contact me for help
- with libgd.
- .SH "Copyright Information"
- .IX Header "Copyright Information"
- The s-1GDs0.pm interface is copyright 1995, Lincoln D. Stein. You are free
- to use it for any purpose, commercial or noncommercial, provided that
- if you redistribute the source code this statement of copyright
- remains attached. The gd library is covered separately under a 1994
- copyright by Quest Protein Database Center, Cold Spring Harbor Labs
- and Thomas Boutell. For usage information see the gd documentation at
- &s-1URLs0
- .PP
- .Vb 1
- & http://www.boutell.com/gd/gd.html
- .Ve
- The latest versions of s-1GDs0.pm are available at
- .PP
- .Vb 2
- & http://www.genome.wi.mit.edu/ftp/pub/software/WWW/GD.html
- & ftp://ftp-genome.wi.mit.edu/pub/software/WWW/GD.pm.tar.gz
- .Ve