{
    "mode": "perldoc",
    "parameter": "GD",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/GD/json",
    "generated": "2026-06-14T04:14:26Z",
    "synopsis": "use GD;\n# create a new image\n$im = GD::Image->new(100,100);\n# allocate some colors\n$white = $im->colorAllocate(255,255,255);\n$black = $im->colorAllocate(0,0,0);\n$red = $im->colorAllocate(255,0,0);\n$blue = $im->colorAllocate(0,0,255);\n# make the background transparent and interlaced\n$im->transparent($white);\n$im->interlaced('true');\n# Put a black frame around the picture\n$im->rectangle(0,0,99,99,$black);\n# Draw a blue oval\n$im->arc(50,50,95,75,0,360,$blue);\n# And fill it with red\n$im->fill(50,50,$red);\n# make sure we are writing to a binary stream\nbinmode STDOUT;\n# Convert the image to PNG and print it on standard output\nprint $im->png;",
    "sections": {
        "NAME": {
            "content": "GD.pm - Interface to Gd Graphics Library\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use GD;\n\n# create a new image\n$im = GD::Image->new(100,100);\n\n# allocate some colors\n$white = $im->colorAllocate(255,255,255);\n$black = $im->colorAllocate(0,0,0);\n$red = $im->colorAllocate(255,0,0);\n$blue = $im->colorAllocate(0,0,255);\n\n# make the background transparent and interlaced\n$im->transparent($white);\n$im->interlaced('true');\n\n# Put a black frame around the picture\n$im->rectangle(0,0,99,99,$black);\n\n# Draw a blue oval\n$im->arc(50,50,95,75,0,360,$blue);\n\n# And fill it with red\n$im->fill(50,50,$red);\n\n# make sure we are writing to a binary stream\nbinmode STDOUT;\n\n# Convert the image to PNG and print it on standard output\nprint $im->png;\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "GD.pm is a Perl interface to Thomas Boutell's gd graphics library (version 2.01 or higher; see\nbelow). GD allows you to create color drawings using a large number of graphics primitives, and\nemit the drawings as PNG files.\n\nGD defines the following four classes:\n\n\"GD::Image\"\nAn image class, which holds the image data and accepts graphic primitive method calls.\n\n\"GD::Font\"\nA font class, which holds static font information and used for text rendering.\n\n\"GD::Polygon\"\nA simple polygon object, used for storing lists of vertices prior to rendering a polygon\ninto an image.\n\n\"GD::Simple\"\nA \"simple\" class that simplifies the GD::Image API and then adds a set of object-oriented\ndrawing methods using turtle graphics, simplified font handling, ability to work in polar\ncoordinates, HSV color spaces, and human-readable color names like \"lightblue\". Please see\nGD::Simple for a description of these methods.\n\nA Simple Example:\n\n#!/usr/bin/perl\n\nuse GD;\n\n# create a new image\n$im = GD::Image->new(100,100);\n\n# allocate some colors\n$white = $im->colorAllocate(255,255,255);\n$black = $im->colorAllocate(0,0,0);\n$red = $im->colorAllocate(255,0,0);\n$blue = $im->colorAllocate(0,0,255);\n\n# make the background transparent and interlaced\n$im->transparent($white);\n$im->interlaced('true');\n\n# Put a black frame around the picture\n$im->rectangle(0,0,99,99,$black);\n\n# Draw a blue oval\n$im->arc(50,50,95,75,0,360,$blue);\n\n# And fill it with red\n$im->fill(50,50,$red);\n\n# make sure we are writing to a binary stream\nbinmode STDOUT;\n\n# Convert the image to PNG and print it on standard output\nprint $im->png;\n\nNotes:\n\n1. To create a new, empty image, send a new() message to GD::Image, passing it the width and\nheight of the image you want to create. An image object will be returned. Other class methods\nallow you to initialize an image from a preexisting JPG, PNG, GD, GD2, XBM or other supported\nimage files.\n2. Next you will ordinarily add colors to the image's color table. colors are added using a",
            "subsections": [
                {
                    "name": "colorAllocate",
                    "content": "triples for the desired color. The method returns the index of that color in the image's color\ntable. You should store these indexes for later use.\n3. Now you can do some drawing! The various graphics primitives are described below. In this\nexample, we do some text drawing, create an oval, and create and draw a polygon.\n4. Polygons are created with a new() message to GD::Polygon. You can add points to the returned\npolygon one at a time using the addPt() method. The polygon can then be passed to an image for\nrendering.\n5. When you're done drawing, you can convert the image into PNG format by sending it a png()\nmessage (or any other supported image format). It will return a (potentially large) scalar value\ncontaining the binary data for the image. Ordinarily you will print it out at this point or\nwrite it to a file. To ensure portability to platforms that differentiate between text and\nbinary files, be sure to call \"binmode()\" on the file you are writing the image to.\n"
                }
            ]
        },
        "Object Constructors: Creating Images": {
            "content": "See GD::Image for the current list of supported Image formats.\n\nThe following class methods allow you to create new GD::Image objects.\n\n$image = GD::Image->new([$width,$height],[$truecolor])\n$image = GD::Image->new(*FILEHANDLE)\n$image = GD::Image->new($filename)\n$image = GD::Image->new($data)\nThe new() method is the main constructor for the GD::Image class. Called with two integer\narguments, it creates a new blank image of the specified width and height. For example:\n\n$myImage = GD::Image->new(100,100) || die;\n\nThis will create an image that is 100 x 100 pixels wide. If you don't specify the\ndimensions, a default of 64 x 64 will be chosen.\n\nThe optional third argument, $truecolor, tells new() to create a truecolor GD::Image object.\nTruecolor images have 24 bits of color data (eight bits each in the red, green and blue\nchannels respectively), allowing for precise photograph-quality color usage. If not\nspecified, the image will use an 8-bit palette for compatibility with older versions of\nlibgd.\n\nAlternatively, you may create a GD::Image object based on an existing image by providing an\nopen filehandle, a filename, or the image data itself. The image formats automatically\nrecognized and accepted are: GIF, PNG, JPEG, XBM, XPM, GD2, TIFF, WEBP, HEIF or AVIF. Other\nformats, including WBMP, and GD version 1, cannot be recognized automatically at this time.\n\nIf something goes wrong (e.g. insufficient memory), this call will return undef.\n\n$image = GD::Image->trueColor([0,1])\nFor backwards compatibility with scripts previous versions of GD, new images created from\nscratch (width, height) are palette based by default. To change this default to create true\ncolor images use:\n\nGD::Image->trueColor(1);\n\nbefore creating new images. To switch back to palette based by default, use:\n\nGD::Image->trueColor(0);\n\n$image = GD::Image->newPalette([$width,$height])\n$image = GD::Image->newTrueColor([$width,$height])\nThe newPalette() and newTrueColor() methods can be used to explicitly create an palette\nbased or true color image regardless of the current setting of trueColor().\n\n$image = GD::Image->newFromPng($file, [$truecolor])\n$image = GD::Image->newFromPngData($data, [$truecolor])\nThe newFromPng() method will create an image from a PNG file read in through the provided\nfilehandle or file path. The filehandle must previously have been opened on a valid PNG file\nor pipe. If successful, this call will return an initialized image which you can then\nmanipulate as you please. If it fails, which usually happens if the thing at the other end\nof the filehandle is not a valid PNG file, the call returns undef. Notice that the call\ndoesn't automatically close the filehandle for you. But it does call \"binmode(FILEHANDLE)\"\nfor you, on platforms where this matters.\n\nYou may use any of the following as the argument:\n\n1) a simple filehandle, such as STDIN\n2) a filehandle glob, such as *PNG\n3) a reference to a glob, such as \\*PNG\n4) an IO::Handle object\n5) the pathname of a file\n\nIn the latter case, newFromPng() will attempt to open the file for you and read the PNG\ninformation from it.\n\nExample1:\n\nopen (PNG,\"barnswallow.png\") || die;\n$myImage = GD::Image->newFromPng(\\*PNG) || die;\nclose PNG;\n\nExample2:\n$myImage = GD::Image->newFromPng('barnswallow.png');\n\nTo get information about the size and color usage of the information, you can call the image\nquery methods described below. Images created by reading PNG images will be truecolor if the\nimage file itself is truecolor. To force the image to be palette-based, pass a value of 0 in\nthe optional $truecolor argument.\n\nThe newFromPngData() method will create a new GD::Image initialized with the PNG format data\ncontained in $data.\n\n$image = GD::Image->newFromJpeg($file, [$truecolor])\n$image = GD::Image->newFromJpegData($data, [$truecolor])\nThese methods will create an image from a JPEG file. They work just like newFromPng() and\nnewFromPngData(), and will accept the same filehandle and pathname arguments.\n\nImages created by reading JPEG images will always be truecolor. To force the image to be\npalette-based, pass a value of 0 in the optional $truecolor argument.\n\n$image = GD::Image->newFromGif($file, [$truecolor])\n$image = GD::Image->newFromGifData($data)\nThese methods will create an image from a GIF file. They work just like newFromPng() and\nnewFromPngData(), and will accept the same filehandle and pathname arguments.\n\nImages created from GIFs are always 8-bit palette images. To convert to truecolor, you must\ncreate a truecolor image and then perform a copy.\n\n$image = GD::Image->newFromXbm($file, [$truecolor])\nThis works in exactly the same way as \"newFromPng\", but reads the contents of an X Bitmap\n(black & white) file:\n\nopen (XBM,\"coredump.xbm\") || die;\n$myImage = GD::Image->newFromXbm(\\*XBM) || die;\nclose XBM;\n\nThere is no newFromXbmData() function, because there is no corresponding function in the gd\nlibrary.\n\n$image = GD::Image->newFromWBMP($file, [$truecolor])\nThis works in exactly the same way as \"newFromPng\", but reads the contents of an Windows BMP\nBitmap file:\n\nopen (BMP,\"coredump.bmp\") || die;\n$myImage = GD::Image->newFromWBMP(\\*BMP) || die;\nclose BMP;\n\nThere is no newFromWBMPData() function, because there is no corresponding function in the gd\nlibrary.\n\n$image = GD::Image->newFromGd($file)\n$image = GD::Image->newFromGdData($data)\nNOTE: GD and GD2 support was dropped witn libgd 2.3.2.\n\nThese methods initialize a GD::Image from a Gd file, filehandle, or data. Gd is Tom\nBoutell's disk-based storage format, intended for the rare case when you need to read and\nwrite the image to disk quickly. It's not intended for regular use, because, unlike PNG or\nJPEG, no image compression is performed and these files can become BIG.\n\n$myImage = GD::Image->newFromGd(\"godzilla.gd\") || die;\nclose GDF;\n\n$image = GD::Image->newFromGd2($file)\n$image = GD::Image->newFromGd2Data($data)\nNOTE: GD and GD2 support was dropped witn libgd 2.3.2.\n\nThis works in exactly the same way as \"newFromGd()\" and newFromGdData, but use the new\ncompressed GD2 image format.\n\n$image = GD::Image->newFromGd2Part($file,srcX,srcY,width,height)\nThis class method allows you to read in just a portion of a GD2 image file. In addition to a\nfilehandle, it accepts the top-left corner and dimensions (width,height) of the region of\nthe image to read. For example:\n\nopen (GDF,\"godzilla.gd2\") || die;\n$myImage = GD::Image->newFromGd2Part(\\*GDF,10,20,100,100) || die;\nclose GDF;\n\nThis reads a 100x100 square portion of the image starting from position (10,20).\n\n$image = GD::Image->newFromXpm($filename)\nThis creates a new GD::Image object starting from a filename. This is unlike the other\nnewFrom() functions because it does not take a filehandle. This difference comes from an\ninconsistency in the underlying gd library.\n\n$myImage = GD::Image->newFromXpm('earth.xpm') || die;\n\nThis function is only available if libgd was compiled with XPM support.\n\nNOTE: The libgd library is unable to read certain XPM files, returning an all-black image\ninstead.\n\n$bool = GD::supportsFileType($filename, $iswriting)\nThis returns a TRUE or FALSE value, if libgd supports reading or when the 2nd argument is 1,\nif libgd supports writing the given filetype, depending on the filename extension. Only with\nlibgd versions >= gd-2.1.1.\n\nAssuming LibGD is compiled with support for these image types, the following extensions are\nsupported:\n\n.gif\n.gd, .gd2\n.wbmp\n.bmp\n.xbm\n.tga\n.png\n.jpg, .jpeg\n.tiff, .tif\n.webp\n.heic, .heix\n.avif\n.xpm\n\nFilenames are parsed case-insensitively. .avifs is not yet suppurted upstream in libavif.\n\nGD::Image Methods\nOnce a GD::Image object is created, you can draw with it, copy it, and merge two images. When\nyou are finished manipulating the object, you can convert it into a standard image file format\nto output or save to a file.\n",
            "subsections": [
                {
                    "name": "Image Data Output Methods",
                    "content": "The following methods convert the internal drawing format into standard output file formats.\n\n$pngdata = $image->png([$compressionlevel])\nThis returns the image data in PNG format. You can then print it, pipe it to a display\nprogram, or write it to a file. Example:\n\n$pngdata = $myImage->png;\nopen (DISPLAY,\"| display -\") || die;\nbinmode DISPLAY;\nprint DISPLAY $pngdata;\nclose DISPLAY;\n\nNote the use of \"binmode()\". This is crucial for portability to DOSish platforms.\n\nThe optional $compressionlevel argument controls the amount of compression to apply to the\noutput PNG image. Values range from 0-9, where 0 means no compression (largest files,\nhighest quality) and 9 means maximum compression (smallest files, worst quality). A\ncompression level of -1 uses the default compression level selected when zlib was compiled\non your system, and is the same as calling png() with no argument. Be careful not to confuse\nthis argument with the jpeg() quality argument, which ranges from 0-100 and has the opposite\nmeaning from compression (higher numbers give higher quality).\n\n$gifdata = $image->gifanimbegin([$GlobalCM [, $Loops]])\nFor libgd version 2.0.33 and higher, this call begins an animated GIF by returning the data\nthat comprises animated gif image file header. After you call this method, call gifanimadd()\none or more times to add the frames of the image. Then call gifanimend(). Each frame must be\nthe same width and height.\n\nA typical sequence will look like this:\n\nmy $gifdata = $image->gifanimbegin;\n$gifdata   .= $image->gifanimadd;    # first frame\nfor (1..100) {\n# make a frame of right size\nmy $frame  = GD::Image->new($image->getBounds);\naddframedata($frame);              # add the data for this frame\n$gifdata   .= $frame->gifanimadd;     # add frame\n}\n$gifdata   .= $image->gifanimend;   # finish the animated GIF\nprint $gifdata;                     # write animated gif to STDOUT\n\nIf you do not wish to store the data in memory, you can print it to stdout or a file.\n\nThe image that you call gifanimbegin on is used to set the image size, color resolution and\ncolor map. If argument $GlobalCM is 1, the image color map becomes the GIF89a global color\nmap. If $Loops is given and >= 0, the NETSCAPE2.0 application extension is created, with\nlooping count. Looping count 0 means forever.\n\n$gifdata = $image->gifanimadd([$LocalCM [, $LeftOfs [, $TopOfs [, $Delay [, $Disposal [,\n$previm]]]]]])\nReturns the data that comprises one animated gif image frame. You can then print it, pipe it\nto a display program, or write it to a file. With $LeftOfs and $TopOfs you can place this\nframe in different offset than (0,0) inside the image screen. Delay between the previous\nframe and this frame is in 1/100s units. Disposal is usually and by default 1. Compression\nis activated by giving the previous image as a parameter. This function then compares the\nimages and only writes the changed pixels to the new frame in animation. The Disposal\nparameter for optimized animations must be set to 1, also for the first frame. $LeftOfs and\n$TopOfs parameters are ignored for optimized frames.\n\n$gifdata = $image->gifanimend()\nReturns the data for end segment of animated gif file. It always returns string ';'. This\nstring must be printed to an animated gif file after all image frames to properly terminate\nit according to GIF file syntax. Image object is not used at all in this method.\n\n$jpegdata = $image->jpeg([$quality])\nThis returns the image data in JPEG format. You can then print it, pipe it to a display\nprogram, or write it to a file. You may pass an optional quality score to jpeg() in order to\ncontrol the JPEG quality. This should be an integer between 0 and 100. Higher quality scores\ngive larger files and better image quality. If you don't specify the quality, jpeg() will\nchoose a good default.\n\n$gifdata = $image->gif().\nThis returns the image data in GIF format. You can then print it, pipe it to a display\nprogram, or write it to a file.\n\n$gddata = $image->gd\nThis returns the image data in GD format. You can then print it, pipe it to a display\nprogram, or write it to a file. Example:\n\nbinmode MYOUTFILE;\nprint MYOUTFILE $myImage->gd;\n\n$gd2data = $image->gd2\nSame as gd(), except that it returns the data in compressed GD2 format.\n\n$wbmpdata = $image->wbmp([$foreground])\nThis returns the image data in WBMP format, which is a black-and-white image format. Provide\nthe index of the color to become the foreground color. All other pixels will be considered\nbackground.\n\n$tiffdata = $image->tiff()\nThis returns the image data in TIFF format.\n\n$webpdata = $image->webp([$quality])\nThis returns the image data in WEBP format, with the optional quality argument. The default\nis 80, also chosen by the value -1. A quality value of >= 101 is considered Lossless.\n\n$webpdata = $image->heif([$quality])\nThis returns the truecolor image data in HEIF format, with the optional quality and speed\narguments. If truecolor is not set, this fails. The default quality is 80, also chosen by\nthe value -1. A quality value of 200 is considered Lossless.\n\n$webpdata = $image->avif([$quality,$speed])\nThis returns the truecolor image data in AVIF format, with the AVif encoder and 444 chroma,\nand the optional quality argument. If truecolor is not set, this fails. The default\ncompression quality 1-100 is -1, the default speed 0-10 is 6.\n\n$success = $image->file($filename)\nWrites an image to a file in the format indicated by the filename, with libgd versions >=\ngd-2.1.1.\n\nFile type is determined by the extension of the file name. See \"supportsFiletype\" for an\noverview of the parsing.\n\nFor file types that require extra arguments, \"file\" attempts to use sane defaults:\n\nC<gdImageGd2> chunk size = 0, compression is enabled.\nC<gdImageJpeg>        quality = -1 (i.e. the reasonable default)\nC<gdImageWBMP>        foreground is the darkest available color\nC<gdImageWEBP>        quality default\nC<gdImageHEIF>        quality default, codes = HEVC, chroma = 444\nC<gdImageAVIF>        quality default, speed = 6\n\nEverything else is called with the two-argument function and so will use the default values.\n\n\"file\" and the underlying libgd \"gdImageFile\" has some rudimentary error detection and will\nreturn FALSE (0) if a detectable error occurred. However, the image loaders do not normally\nreturn their error status so a result of TRUE (1) does not mean the file was saved\nsuccessfully.\n"
                },
                {
                    "name": "Color Control",
                    "content": "These methods allow you to control and manipulate the GD::Image color table for palette,\nnon-truecolor images.\n\n$index = $image->colorAllocate(red,green,blue)\nThis allocates a color with the specified red, green and blue components and returns its\nindex in the color table, if specified. The first color allocated in this way becomes the\nimage's background color. (255,255,255) is white (all pixels on). (0,0,0) is black (all\npixels off). (255,0,0) is fully saturated red. (127,127,127) is 50% gray. You can find\nplenty of examples in /usr/X11/lib/X11/rgb.txt.\n\nIf no colors are allocated, then this function returns -1.\n\nExample:\n\n$black = $myImage->colorAllocate(0,0,0); #background color\n$white = $myImage->colorAllocate(255,255,255);\n$peachpuff = $myImage->colorAllocate(255,218,185);\n\n$index = $image->colorAllocateAlpha(reg,green,blue,alpha)\nThis allocates a color with the specified red, green, and blue components, plus the\nspecified alpha channel. The alpha value may range from 0 (opaque) to 127 (transparent). The\n\"alphaBlending\" function changes the way this alpha channel affects the resulting image.\n\n$image->colorDeallocate(colorIndex)\nThis marks the color at the specified index as being ripe for reallocation. The next time\ncolorAllocate is used, this entry will be replaced. You can call this method several times\nto deallocate multiple colors. There's no function result from this call.\n\nExample:\n\n$myImage->colorDeallocate($peachpuff);\n$peachy = $myImage->colorAllocate(255,210,185);\n\n$index = $image->colorClosest(red,green,blue)\nThis returns the index of the color closest in the color table to the red green and blue\ncomponents specified. If no colors have yet been allocated, then this call returns -1.\n\nExample:\n\n$apricot = $myImage->colorClosest(255,200,180);\n\n$index = $image->colorClosestAlpha(red,green,blue,alpha)\nThis returns the index of the color closest in the color table to the red green blue and\nalpha components specified. If no colors have yet been allocated, then this call returns -1.\n\nExample:\n\n$apricot = $myImage->colorClosestAlpha(255,200,180,0);\n\n$index = $image->colorClosestHWB(red,green,blue)\nThis also attempts to return the color closest in the color table to the red green and blue\ncomponents specified. It uses a Hue/White/Black color representation to make the selected\ncolor more likely to match human perceptions of similar colors.\n\nIf no colors have yet been allocated, then this call returns -1.\n\nExample:\n\n$mostred = $myImage->colorClosestHWB(255,0,0);\n\n$index = $image->colorExact(red,green,blue)\nThis returns the index of a color that exactly matches the specified red green and blue\ncomponents. If such a color is not in the color table, this call returns -1.\n\n$rosey = $myImage->colorExact(255,100,80);\nwarn \"Everything's coming up roses.\\n\" if $rosey >= 0;\n\n$index = $image->colorExactAlpha(red,green,blue,alpha)\nThis returns the index of a color that exactly matches the specified red green blue and\nalpha components. If such a color is not in the color table, this call returns -1.\n\n$rosey = $myImage->colorExactAlpha(255,100,80,0);\nwarn \"Everything's coming up roses.\\n\" if $rosey >= 0;\n\n$index = $image->colorResolve(red,green,blue)\nThis returns the index of a color that exactly matches the specified red green and blue\ncomponents. If such a color is not in the color table and there is room, then this method\nallocates the color in the color table and returns its index.\n\n$rosey = $myImage->colorResolve(255,100,80);\nwarn \"Everything's coming up roses.\\n\" if $rosey >= 0;\n\n$index = $image->colorResolveAlpha(red,green,blue,alpha)\nThis returns the index of a color that exactly matches the specified red green blue and\nalpha components. If such a color is not in the color table and there is room, then this\nmethod allocates the color in the color table and returns its index.\n\n$rosey = $myImage->colorResolveAlpha(255,100,80,0);\nwarn \"Everything's coming up roses.\\n\" if $rosey >= 0;\n\n$colorsTotal = $image->colorsTotal *object method*\nThis returns the total number of colors allocated in the object.\n\n$maxColors = $myImage->colorsTotal;\n\nIn the case of a TrueColor image, this call will return undef.\n\n$index = $image->getPixel(x,y) *object method*\nThis returns the color table index underneath the specified point. It can be combined with\nrgb() to obtain the rgb color underneath the pixel.\n\nExample:\n\n$index = $myImage->getPixel(20,100);\n($r,$g,$b) = $myImage->rgb($index);\n\n($red,$green,$blue) = $image->rgb($index)\nThis returns a list containing the red, green and blue components of the specified color\nindex.\n\nExample:\n\n@RGB = $myImage->rgb($peachy);\n\n($alpha) = $image->alpha($index)\nThis returns an item containing the alpha component of the specified color index.\n\nExample:\n\n@RGB = $myImage->rgb($peachy);\n\n$image->transparent($colorIndex)\nThis marks the color at the specified index as being transparent. Portions of the image\ndrawn in this color will be invisible. This is useful for creating paintbrushes of odd\nshapes, as well as for making PNG backgrounds transparent for displaying on the Web. Only\none color can be transparent at any time. To disable transparency, specify -1 for the index.\n\nIf you call this method without any parameters, it will return the current index of the\ntransparent color, or -1 if none.\n\nExample:\n\nopen(PNG,\"test.png\");\n$im = GD::Image->newFromPng(PNG);\n$white = $im->colorClosest(255,255,255); # find white\n$im->transparent($white);\nbinmode STDOUT;\nprint $im->png;\n"
                },
                {
                    "name": "Special Colors",
                    "content": "GD implements a number of special colors that can be used to achieve special effects. They are\nconstants defined in the GD:: namespace, but automatically exported into your namespace when the\nGD module is loaded.\n\n$image->setBrush($image)\nYou can draw lines and shapes using a brush pattern. Brushes are just palette, not\nTrueColor, images that you can create and manipulate in the usual way. When you draw with\nthem, their contents are used for the color and shape of the lines.\n\nTo make a brushed line, you must create or load the brush first, then assign it to the image\nusing setBrush(). You can then draw in that with that brush using the gdBrushed special\ncolor. It's often useful to set the background of the brush to transparent so that the\nnon-colored parts don't overwrite other parts of your image.\n\nExample:\n\n# Create a brush at an angle\n$diagonalbrush = GD::Image->new(5,5);\n$white = $diagonalbrush->colorAllocate(255,255,255);\n$black = $diagonalbrush->colorAllocate(0,0,0);\n$diagonalbrush->transparent($white);\n$diagonalbrush->line(0,4,4,0,$black); # NE diagonal\n\n# Set the brush\n$myImage->setBrush($diagonalbrush);\n\n# Draw a circle using the brush\n$myImage->arc(50,50,25,25,0,360,gdBrushed);\n\n$image->setThickness($thickness)\nLines drawn with line(), rectangle(), arc(), and so forth are 1 pixel thick by default. Call\nsetThickness() to change the line drawing width.\n\n$image->setStyle(@colors)\nStyled lines consist of an arbitrary series of repeated colors and are useful for generating\ndotted and dashed lines. To create a styled line, use setStyle() to specify a repeating\nseries of colors. It accepts an array consisting of one or more color indexes. Then draw\nusing the gdStyled special color. Another special color, gdTransparent can be used to\nintroduce holes in the line, as the example shows.\n\nExample:\n\n# Set a style consisting of 4 pixels of yellow,\n# 4 pixels of blue, and a 2 pixel gap\n$myImage->setStyle($yellow,$yellow,$yellow,$yellow,\n$blue,$blue,$blue,$blue,\ngdTransparent,gdTransparent);\n$myImage->arc(50,50,25,25,0,360,gdStyled);\n\nTo combine the \"gdStyled\" and \"gdBrushed\" behaviors, you can specify \"gdStyledBrushed\". In\nthis case, a pixel from the current brush pattern is rendered wherever the color specified\nin setStyle() is neither gdTransparent nor 0.\n\ngdTiled\nDraw filled shapes and flood fills using a pattern. The pattern is just another image. The\nimage will be tiled multiple times in order to fill the required space, creating wallpaper\neffects. You must call \"setTile\" in order to define the particular tile pattern you'll use\nfor drawing when you specify the gdTiled color. details.\n\ngdStyled\nThe gdStyled color is used for creating dashed and dotted lines. A styled line can contain\nany series of colors and is created using the setStyled() command.\n\ngdAntiAliased\nThe \"gdAntiAliased\" color is used for drawing lines with antialiasing turned on.\nAntialiasing will blend the jagged edges of lines with the background, creating a smoother\nlook. The actual color drawn is set with setAntiAliased().\n\n$image->setAntiAliased($color)\n\"Antialiasing\" is a process by which jagged edges associated with line drawing can be\nreduced by blending the foreground color with an appropriate percentage of the background,\ndepending on how much of the pixel in question is actually within the boundaries of the line\nbeing drawn. All line-drawing methods, such as line() and polygon, will draw antialiased\nlines if the special \"color\" gdAntiAliased is used when calling them.\n\nsetAntiAliased() is used to specify the actual foreground color to be used when drawing\nantialiased lines. You may set any color to be the foreground, however as of libgd version\n2.0.12 an alpha channel component is not supported.\n\nAntialiased lines can be drawn on both truecolor and palette-based images. However, attempts\nto draw antialiased lines on highly complex palette-based backgrounds may not give\nsatisfactory results, due to the limited number of colors available in the palette.\nAntialiased line-drawing on simple backgrounds should work well with palette-based images;\notherwise create or fetch a truecolor image instead. When using palette-based images, be\nsure to allocate a broad spectrum of colors in order to have sufficient colors for the\nantialiasing to use.\n\n$image->setAntiAliasedDontBlend($color,[$flag])\nNormally, when drawing lines with the special gdAntiAliased \"color,\" blending with the\nbackground to reduce jagged edges is the desired behavior. However, when it is desired that\nlines not be blended with one particular color when it is encountered in the background, the\nsetAntiAliasedDontBlend() method can be used to indicate the special color that the\nforeground should stand out more clearly against.\n\nOnce turned on, you can turn this feature off by calling setAntiAliasedDontBlend() with a\nsecond argument of 0:\n\n$image->setAntiAliasedDontBlend($color,0);\n"
                },
                {
                    "name": "Drawing Commands",
                    "content": "These methods allow you to draw lines, rectangles, and ellipses, as well as to perform various\nspecial operations like flood-fill.\n\n$image->setPixel($x,$y,$color)\nThis sets the pixel at (x,y) to the specified color index. No value is returned from this\nmethod. The coordinate system starts at the upper left at (0,0) and gets larger as you go\ndown and to the right. You can use a real color, or one of the special colors gdBrushed,\ngdStyled and gdStyledBrushed can be specified.\n\nExample:\n\n# This assumes $peach already allocated\n$myImage->setPixel(50,50,$peach);\n\n$image->line($x1,$y1,$x2,$y2,$color)\nThis draws a line from (x1,y1) to (x2,y2) of the specified color. You can use a real color,\nor one of the special colors gdBrushed, gdStyled and gdStyledBrushed.\n\nExample:\n\n# Draw a diagonal line using the currently defined\n# paintbrush pattern.\n$myImage->line(0,0,150,150,gdBrushed);\n\n$image->dashedLine($x1,$y1,$x2,$y2,$color)\nDEPRECATED: The libgd library provides this method solely for backward compatibility with\nlibgd version 1.0, and there have been reports that it no longer works as expected. Please\nuse the setStyle() and gdStyled methods as described below.\n\nThis draws a dashed line from (x1,y1) to (x2,y2) in the specified color. A more powerful way\nto generate arbitrary dashed and dotted lines is to use the setStyle() method described\nbelow and to draw with the special color gdStyled.\n\nExample:\n\n$myImage->dashedLine(0,0,150,150,$blue);\n\n$image->rectangle($x1,$y1,$x2,$y2,$color)\nThis draws a rectangle with the specified color. (x1,y1) and (x2,y2) are the upper left and\nlower right corners respectively. Both real color indexes and the special colors gdBrushed,\ngdStyled and gdStyledBrushed are accepted.\n\nExample:\n\n$myImage->rectangle(10,10,100,100,$rose);\n\n$image->filledRectangle($x1,$y1,$x2,$y2,$color) =item $image->setTile($otherimage)\nThis draws a rectangle filled with the specified color. You can use a real color, or the\nspecial fill color gdTiled to fill the polygon with a pattern.\n\nExample:\n\n# read in a fill pattern and set it\n$tile = GD::Image->newFromPng('happyface.png');\n$myImage->setTile($tile);\n\n# draw the rectangle, filling it with the pattern\n$myImage->filledRectangle(10,10,150,200,gdTiled);\n\n$image->openPolygon($polygon,$color)\nThis draws a polygon with the specified color. The polygon must be created first (see\nbelow). The polygon must have at least three vertices. If the last vertex doesn't close the\npolygon, the method will close it for you. Both real color indexes and the special colors\ngdBrushed, gdStyled and gdStyledBrushed can be specified.\n\nExample:\n\n$poly = GD::Polygon->new;\n$poly->addPt(50,0);\n$poly->addPt(99,99);\n$poly->addPt(0,99);\n$myImage->openPolygon($poly,$blue);\n\n$image->unclosedPolygon($polygon,$color)\nThis draws a sequence of connected lines with the specified color, without connecting the\nfirst and last point to a closed polygon. The polygon must be created first (see below). The\npolygon must have at least three vertices. Both real color indexes and the special colors\ngdBrushed, gdStyled and gdStyledBrushed can be specified.\n\nYou need libgd 2.0.33 or higher to use this feature.\n\nExample:\n\n$poly = GD::Polygon->new;\n$poly->addPt(50,0);\n$poly->addPt(99,99);\n$poly->addPt(0,99);\n$myImage->unclosedPolygon($poly,$blue);\n\n$image->filledPolygon($poly,$color)\nThis draws a polygon filled with the specified color. You can use a real color, or the\nspecial fill color gdTiled to fill the polygon with a pattern.\n\nExample:\n\n# make a polygon\n$poly = GD::Polygon->new;\n$poly->addPt(50,0);\n$poly->addPt(99,99);\n$poly->addPt(0,99);\n\n# draw the polygon, filling it with a color\n$myImage->filledPolygon($poly,$peachpuff);\n\n$image->ellipse($cx,$cy,$width,$height,$color)\n$image->filledEllipse($cx,$cy,$width,$height,$color)\nThese methods() draw ellipses. ($cx,$cy) is the center of the arc, and ($width,$height)\nspecify the ellipse width and height, respectively. filledEllipse() is like Ellipse() except\nthat the former produces filled versions of the ellipse.\n\n$image->arc($cx,$cy,$width,$height,$start,$end,$color)\nThis draws arcs and ellipses. (cx,cy) are the center of the arc, and (width,height) specify\nthe width and height, respectively. The portion of the ellipse covered by the arc are\ncontrolled by start and end, both of which are given in degrees from 0 to 360. Zero is at\nthe right end of the ellipse, and angles increase clockwise. To specify a complete ellipse,\nuse 0 and 360 as the starting and ending angles. To draw a circle, use the same value for\nwidth and height.\n\nYou can specify a normal color or one of the special colors gdBrushed, gdStyled, or\ngdStyledBrushed.\n\nExample:\n\n# draw a semicircle centered at 100,100\n$myImage->arc(100,100,50,50,0,180,$blue);\n\n$image->filledArc($cx,$cy,$width,$height,$start,$end,$color [,$arcstyle])\nThis method is like arc() except that it colors in the pie wedge with the selected color.\n$arcstyle is optional. If present it is a bitwise OR of the following constants:\n\ngdArc           connect start & end points of arc with a rounded edge\ngdChord         connect start & end points of arc with a straight line\ngdPie           synonym for gdChord\ngdNoFill        outline the arc or chord\ngdEdged         connect beginning and ending of the arc to the center\n\ngdArc and gdChord are mutually exclusive. gdChord just connects the starting and ending\nangles with a straight line, while gdArc produces a rounded edge. gdPie is a synonym for\ngdArc. gdNoFill indicates that the arc or chord should be outlined, not filled. gdEdged,\nused together with gdNoFill, indicates that the beginning and ending angles should be\nconnected to the center; this is a good way to outline (rather than fill) a \"pie slice.\"\n\nExample:\n\n$image->filledArc(100,100,50,50,0,90,$blue,gdEdged|gdNoFill);\n\n$image->fill($x,$y,$color)\nThis method flood-fills regions with the specified color. The color will spread through the\nimage, starting at point (x,y), until it is stopped by a pixel of a different color from the\nstarting pixel (this is similar to the \"paintbucket\" in many popular drawing toys). You can\nspecify a normal color, or the special color gdTiled, to flood-fill with patterns.\n\nExample:\n\n# Draw a rectangle, and then make its interior blue\n$myImage->rectangle(10,10,100,100,$black);\n$myImage->fill(50,50,$blue);\n\n$image->fillToBorder($x,$y,$bordercolor,$color)\nLike \"fill\", this method flood-fills regions with the specified color, starting at position\n(x,y). However, instead of stopping when it hits a pixel of a different color than the\nstarting pixel, flooding will only stop when it hits the color specified by bordercolor. You\nmust specify a normal indexed color for the bordercolor. However, you are free to use the\ngdTiled color for the fill.\n\nExample:\n\n# This has the same effect as the previous example\n$myImage->rectangle(10,10,100,100,$black);\n$myImage->fillToBorder(50,50,$black,$blue);\n"
                },
                {
                    "name": "Image Copying Commands",
                    "content": "Two methods are provided for copying a rectangular region from one image to another. One method\ncopies a region without resizing it. The other allows you to stretch the region during the copy\noperation.\n\nWith either of these methods it is important to know that the routines will attempt to flesh out\nthe destination image's color table to match the colors that are being copied from the source.\nIf the destination's color table is already full, then the routines will attempt to find the\nbest match, with varying results.\n\n$image->copy($sourceImage,$dstX,$dstY,$srcX,$srcY,$width,$height)\nThis is the simplest of the several copy operations, copying the specified region from the\nsource image to the destination image (the one performing the method call). (srcX,srcY)\nspecify the upper left corner of a rectangle in the source image, and (width,height) give\nthe width and height of the region to copy. (dstX,dstY) control where in the destination\nimage to stamp the copy. You can use the same image for both the source and the destination,\nbut the source and destination regions must not overlap or strange things will happen.\n\nExample:\n\n$myImage = GD::Image->new(100,100);\n... various drawing stuff ...\n$srcImage = GD::Image->new(50,50);\n... more drawing stuff ...\n# copy a 25x25 pixel region from $srcImage to\n# the rectangle starting at (10,10) in $myImage\n$myImage->copy($srcImage,10,10,0,0,25,25);\n\n$image->clone()\nMake a copy of the image and return it as a new object. The new image will look identical.\nHowever, it may differ in the size of the color palette and other nonessential details.\n\nExample:\n\n$myImage = GD::Image->new(100,100);\n... various drawing stuff ...\n$copy = $myImage->clone;\n\n$image->copyMerge($sourceImage,$dstX,$dstY,\n$srcX,$srcY,$width,$height,$percent)\n\nThis copies the indicated rectangle from the source image to the destination image, merging\nthe colors to the extent specified by percent (an integer between 0 and 100). Specifying\n100% has the same effect as copy() -- replacing the destination pixels with the source\nimage. This is most useful for highlighting an area by merging in a solid rectangle.\n\nExample:\n\n$myImage = GD::Image->new(100,100);\n... various drawing stuff ...\n$redImage = GD::Image->new(50,50);\n... more drawing stuff ...\n# copy a 25x25 pixel region from $srcImage to\n# the rectangle starting at (10,10) in $myImage, merging 50%\n$myImage->copyMerge($srcImage,10,10,0,0,25,25,50);\n\n$image->copyMergeGray($sourceImage,$dstX,$dstY,\n$srcX,$srcY,$width,$height,$percent)\n\nThis is identical to copyMerge() except that it preserves the hue of the source by\nconverting all the pixels of the destination rectangle to grayscale before merging.\n\n$image->copyResized($sourceImage,$dstX,$dstY,\n$srcX,$srcY,$destW,$destH,$srcW,$srcH)\n\nThis method is similar to copy() but allows you to choose different sizes for the source and\ndestination rectangles. The source and destination rectangle's are specified independently\nby (srcW,srcH) and (destW,destH) respectively. copyResized() will stretch or shrink the\nimage to accommodate the size requirements.\n\nExample:\n\n$myImage = GD::Image->new(100,100);\n... various drawing stuff ...\n$srcImage = GD::Image->new(50,50);\n... more drawing stuff ...\n# copy a 25x25 pixel region from $srcImage to\n# a larger rectangle starting at (10,10) in $myImage\n$myImage->copyResized($srcImage,10,10,0,0,50,50,25,25);\n\n$image->copyResampled($sourceImage,$dstX,$dstY,\n$srcX,$srcY,$destW,$destH,$srcW,$srcH)\n\nThis method is similar to copyResized() but provides \"smooth\" copying from a large image to\na smaller one, using a weighted average of the pixels of the source area rather than\nselecting one representative pixel. This method is identical to copyResized() when the\ndestination image is a palette image.\n\n$image->copyRotated($sourceImage,$dstX,$dstY,\n$srcX,$srcY,$width,$height,$angle)\n\nLike copyResized() but the $angle argument specifies an arbitrary amount to rotate the image\ncounter clockwise (in degrees). In addition, $dstX and $dstY species the center of the\ndestination image, and not the top left corner.\n\n$image->trueColorToPalette([$dither], [$colors])\nThis method converts a truecolor image to a palette image. The code for this function was\noriginally drawn from the Independent JPEG Group library code, which is excellent. The code\nhas been modified to preserve as much alpha channel information as possible in the resulting\npalette, in addition to preserving colors as well as possible. This does not work as well as\nmight be hoped. It is usually best to simply produce a truecolor output image instead, which\nguarantees the highest output quality. Both the dithering (0/1, default=0) and maximum\nnumber of colors used (<=256, default = gdMaxColors) can be specified.\n\n$image = $sourceImage->createPaletteFromTrueColor([$dither], [$colors])\nCreates a new palette image from a truecolor image. Same as above, but returns a new image.\n\nDon't use these function -- write real truecolor PNGs and JPEGs. The disk space gain of\nconversion to palette is not great (for small images it can be negative) and the quality\nloss is ugly.\n\n$error = $image->colorMatch($otherimage)\nBring the palette colors in $otherimage to be closer to truecolor $image. A negative return\nvalue is a failure.\n\n-1 image must be True Color\n-2 otherimage must be indexed\n-3 the images are meant to be the same dimensions\n-4 At least 1 color in otherimage must be allocated\n\nThis method is only available with libgd >= 2.1.0\n\n$image = $sourceImage->neuQuant($maxcolor=256,$samplefactor=5)\nCreates a new palette image from a truecolor image.\n\nsamplefactor The quantization precision between 1 (highest quality) and 10 (fastest).\nmaxcolor The number of desired palette entries.\n\nThis is the same as createPaletteFromTrueColor with the quantization method\nGDQUANTNEUQUANT. This does not support dithering. This method is only available with libgd\n>= 2.1.0\n"
                },
                {
                    "name": "Image Transformation Commands",
                    "content": "Gd provides these simple image transformations, non-interpolated.\n\n$image = $sourceImage->copyRotate90()\n$image = $sourceImage->copyRotate180()\n$image = $sourceImage->copyRotate270()\n$image = $sourceImage->copyFlipHorizontal()\n$image = $sourceImage->copyFlipVertical()\n$image = $sourceImage->copyTranspose()\n$image = $sourceImage->copyReverseTranspose()\nThese methods can be used to rotate, flip, or transpose an image. The result of the method\nis a copy of the image.\n\n$image->rotate180()\n$image->flipHorizontal()\n$image->flipVertical()\nThese methods are similar to the copy* versions, but instead modify the image in place.\n"
                },
                {
                    "name": "Image Interpolation Methods",
                    "content": "Since libgd 2.1.0 there are better transformation methods, with these interpolation methods:\n\nGDBELL                - Bell\nGDBESSEL              - Bessel\nGDBILINEARFIXED      - fixed point bilinear\nGDBICUBIC             - Bicubic\nGDBICUBICFIXED       - fixed point bicubic integer\nGDBLACKMAN            - Blackman\nGDBOX                 - Box\nGDBSPLINE             - BSpline\nGDCATMULLROM          - Catmullrom\nGDGAUSSIAN            - Gaussian\nGDGENERALIZEDCUBIC   - Generalized cubic\nGDHERMITE             - Hermite\nGDHAMMING             - Hamming\nGDHANNING             - Hannig\nGDMITCHELL            - Mitchell\nGDNEARESTNEIGHBOUR   - Nearest neighbour interpolation\nGDPOWER               - Power\nGDQUADRATIC           - Quadratic\nGDSINC                - Sinc\nGDTRIANGLE            - Triangle\nGDWEIGHTED4           - 4 pixels weighted bilinear interpolation\nGDLINEAR              - bilinear interpolation\n\n$image->interpolationMethod( [$method] )\nGets or sets the interpolation methods for all subsequent interpolations. See above for the\nvalid values. Only available since libgd 2.2.0\n\n$image->copyScaleInterpolated( width, height )\nReturns a copy, using interpolation.\n\n$image->copyRotateInterpolated( angle, bgcolor )\nReturns a copy, using interpolation.\n"
                },
                {
                    "name": "Image Filter Commands",
                    "content": "Gd also provides some common image filters, they modify the image in place and return TRUE if\nmodified or FALSE if not. Most of them need libgd >= 2.1.0, with older versions those functions\nare undefined.\n\n$ok = $image->scatter($sub, $plus)\nif $sub and $plus are 0, nothing is changed, TRUE is returned. if $sub >= $plus, nothing is\nchanged, FALSE is returned. else random pixels are changed.\n\n$ok = $image->scatterColor($sub, $plus, @colors)\nSimilar to scatter, but using the given array of colors, i.e. palette indices.\n\n$ok = $image->pixelate($blocksize, $mode)\nif $blocksize <= 0, nothing is changed, FALSE is returned. if $blocksize == 1, nothing is\nchanged, TRUE is returned. else the following modes are observed: GDPIXELATEUPPERLEFT\nGDPIXELATEAVERAGE\n\n$ok = $image->negate()\n$ok = $image->grayscale()\n$ok = $image->brightness($add)\n$add: -255..255\n\n$ok = $image->contrast($contrast)\n$contrast: a double value. The contrast adjustment value. Negative values increase, positive\nvalues decrease the contrast. The larger the absolute value, the stronger the effect.\n\n$ok = $image->color($red,$green,$blue,$alpha)\nChange channel values of an image.\n\n$red   - The value to add to the red channel of all pixels.\n$green - The value to add to the green channel of all pixels.\n$blue  - The value to add to the blue channel of all pixels.\n$alpha - The value to add to the alpha channel of all pixels.\n\n$ok = $image->selectiveBlur()\n$ok = $image->edgeDetectQuick()\n$ok = $image->gaussianBlur()\n$ok = $image->emboss()\n$ok = $image->meanRemoval()\n$ok = $image->smooth($weight)\n$image = $sourceImage->copyGaussianBlurred($radius, $sigma)\n$radius: int, the blur radius (*not* diameter--range is 2*radius + 1) a radius, not a\ndiameter so a radius of 2 (for example) will blur across a region 5 pixels across (2 to the\ncenter, 1 for the center itself and another 2 to the other edge).\n\n$sigma: the sigma value or a value <= 0.0 to use the computed default. represents the\n\"fatness\" of the curve (lower == fatter).\n\nThe result is always truecolor.\n"
                },
                {
                    "name": "Character and String Drawing",
                    "content": "GD allows you to draw characters and strings, either in normal horizontal orientation or rotated\n90 degrees. These routines use a GD::Font object, described in more detail below. There are four\nbuilt-in monospaced fonts, available in the global variables gdGiantFont, gdLargeFont,\ngdMediumBoldFont, gdSmallFont and gdTinyFont.\n\nIn addition, you can use the load() method to load GD-formatted bitmap font files at runtime.\nYou can create these bitmap files from X11 BDF-format files using the bdf2gd.pl script, which\nshould have been installed with GD (see the bdfscripts directory if it wasn't). The format\nhappens to be identical to the old-style MSDOS bitmap \".fnt\" files, so you can use one of those\ndirectly if you happen to have one.\n\nFor writing proportional scalable fonts, GD offers the stringFT() method, which allows you to\nload and render any TrueType font on your system.\n\n$image->string($font,$x,$y,$string,$color)\nThis method draws a string starting at position (x,y) in the specified font and color. Your\nchoices of fonts are gdSmallFont, gdMediumBoldFont, gdTinyFont, gdLargeFont and gdGiantFont.\n\nExample:\n\n$myImage->string(gdSmallFont,2,10,\"Peachy Keen\",$peach);\n\n$image->stringUp($font,$x,$y,$string,$color)\nJust like the previous call, but draws the text rotated counterclockwise 90 degrees.\n\n$image->char($font,$x,$y,$char,$color)\n$image->charUp($font,$x,$y,$char,$color)\nThese methods draw single characters at position (x,y) in the specified font and color.\nThey're carry-overs from the C interface, where there is a distinction between characters\nand strings. Perl is insensible to such subtle distinctions.\n\n$font = GD::Font->load($fontfilepath)\nThis method dynamically loads a font file, returning a font that you can use in subsequent\ncalls to drawing methods. For example:\n\nmy $courier = GD::Font->load('./courierR12.fnt') or die \"Can't load font\";\n$image->string($courier,2,10,\"Peachy Keen\",$peach);\n\nFont files must be in GD binary format, as described above.\n\n@bounds = $image->stringFT($fgcolor,$fontname,$ptsize,$angle,$x,$y,$string)\n@bounds = GD::Image->stringFT($fgcolor,$fontname,$ptsize,$angle,$x,$y,$string)\n@bounds = $image->stringFT($fgcolor,$fontname,$ptsize,$angle,$x,$y,$string,\\%options)\nThis method uses TrueType to draw a scaled, antialiased string using the TrueType vector\nfont of your choice. It requires that libgd to have been compiled with TrueType support, and\nfor the appropriate TrueType font to be installed on your system.\n\nThe arguments are as follows:\n\nfgcolor    Color index to draw the string in\nfontname   A path to the TrueType (.ttf) font file or a font pattern.\nptsize     The desired point size (may be fractional)\nangle      The rotation angle, in radians (positive values rotate counter clockwise)\nx,y        X and Y coordinates to start drawing the string\nstring     The string itself\n\nIf successful, the method returns an eight-element list giving the boundaries of the\nrendered string:\n\n@bounds[0,1]  Lower left corner (x,y)\n@bounds[2,3]  Lower right corner (x,y)\n@bounds[4,5]  Upper right corner (x,y)\n@bounds[6,7]  Upper left corner (x,y)\n\nIn case of an error (such as the font not being available, or FT support not being\navailable), the method returns an empty list and sets $@ to the error message.\n\nThe fontname argument is the name of the font, which can be a full pathname to a .ttf file,\nor if not the paths in $ENV{GDFONTPATH} will be searched or if empty the libgd compiled\nDEFAULTFONTPATH. The TrueType extensions .ttf, .pfa, .pfb or .dfont can be omitted.\n\nThe string may contain UTF-8 sequences like: \"&#192;\"\n\nYou may also call this method from the GD::Image class name, in which case it doesn't do any\nactual drawing, but returns the bounding box using an inexpensive operation. You can use\nthis to perform layout operations prior to drawing.\n\nUsing a negative color index will disable antialiasing, as described in the libgd manual\npage at <http://www.boutell.com/gd/manual2.0.9.html#gdImageStringFT>.\n\nAn optional 8th argument allows you to pass a hashref of options to stringFT(). Several\nhashkeys are recognized: linespacing, charmap, resolution, and kerning.\n\nThe value of linespacing is supposed to be a multiple of the character height, so setting\nlinespacing to 2.0 will result in double-spaced lines of text. However the current version\nof libgd (2.0.12) does not do this. Instead the linespacing seems to be double what is\nprovided in this argument. So use a spacing of 0.5 to get separation of exactly one line of\ntext. In practice, a spacing of 0.6 seems to give nice results. Another thing to watch out\nfor is that successive lines of text should be separated by the \"\\r\\n\" characters, not just\n\"\\n\".\n\nThe value of charmap is one of \"Unicode\", \"ShiftJIS\" and \"Big5\". The interaction between\nPerl, Unicode and libgd is not clear to me, and you should experiment a bit if you want to\nuse this feature.\n\nThe value of resolution is the vertical and horizontal resolution, in DPI, in the format\n\"hdpi,vdpi\". If present, the resolution will be passed to the Freetype rendering engine as a\nhint to improve the appearance of the rendered font.\n\nThe value of kerning is a flag. Set it to false to turn off the default kerning of text.\n\nExample:\n\n$gd->stringFT($black,'/c/windows/Fonts/pala.ttf',40,0,20,90,\n\"hi there\\r\\nbye now\",\n{linespacing=>0.6,\ncharmap  => 'Unicode',\n});\n\nIf GD was compiled with fontconfig support, and the fontconfig library is available on your\nsystem, then you can use a font name pattern instead of a path. Patterns are described in\nfontconfig and will look something like this \"Times:italic\". For backward compatibility,\nthis feature is disabled by default. You must enable it by calling useFontConfig(1) prior to\nthe stringFT() call.\n\n$image->useFontConfig(1);\n\nFor backward compatibility with older versions of the FreeType library, the alias\nstringTTF() is also recognized.\n\n$hasfontconfig = $image->useFontConfig($flag)\nCall useFontConfig() with a value of 1 in order to enable support for fontconfig font\npatterns (see stringFT). Regardless of the value of $flag, this method will return a true\nvalue if the fontconfig library is present, or false otherwise.\n\nThis method can also be called as a class method of GD::Image;\n\n$result =\n$image->stringFTCircle($cx,$cy,$radius,$textRadius,$fillPortion,$font,$points,$top,$bottom,$fgco\nlor)\nThis draws text in a circle. Currently (libgd 2.0.33) this function does not work for me,\nbut the interface is provided for completeness. The call signature is somewhat complex. Here\nis an excerpt from the libgd manual page:\n\nDraws the text strings specified by top and bottom on the image, curved along the edge of a\ncircle of radius radius, with its center at cx and cy. top is written clockwise along the\ntop; bottom is written counterclockwise along the bottom. textRadius determines the \"height\"\nof each character; if textRadius is 1/2 of radius, characters extend halfway from the edge\nto the center. fillPortion varies from 0 to 1.0, with useful values from about 0.4 to 0.9,\nand determines how much of the 180 degrees of arc assigned to each section of text is\nactually occupied by text; 0.9 looks better than 1.0 which is rather crowded. font is a\nfreetype font; see gdImageStringFT. points is passed to the freetype engine and has an\neffect on hinting; although the size of the text is determined by radius, textRadius, and\nfillPortion, you should pass a point size that \"hints\" appropriately -- if you know the text\nwill be large, pass a large point size such as 24.0 to get the best results. fgcolor can be\nany color, and may have an alpha component, do blending, etc.\n\nReturns a true value on success.\n"
                },
                {
                    "name": "Alpha channels",
                    "content": "The alpha channel methods allow you to control the way drawings are processed according to the\nalpha channel. When true color is turned on, colors are encoded as four bytes, in which the last\nthree bytes are the RGB color values, and the first byte is the alpha channel. Therefore the\nhexadecimal representation of a non transparent RGB color will be: C=0x00(rr)(bb)(bb)\n\nWhen alpha blending is turned on, you can use the first byte of the color to control the\ntransparency, meaning that a rectangle painted with color 0x00(rr)(bb)(bb) will be opaque, and\nanother one painted with 0x7f(rr)(gg)(bb) will be transparent. The Alpha value must be >= 0 and\n<= 0x7f.\n\n$image->alphaBlending($integer)\nThe alphaBlending() method allows for two different modes of drawing on truecolor images. In\nblending mode, which is on by default (libgd 2.0.2 and above), the alpha channel component\nof the color supplied to all drawing functions, such as \"setPixel\", determines how much of\nthe underlying color should be allowed to shine through. As a result, GD automatically\nblends the existing color at that point with the drawing color, and stores the result in the\nimage. The resulting pixel is opaque. In non-blending mode, the drawing color is copied\nliterally with its alpha channel information, replacing the destination pixel. Blending mode\nis not available when drawing on palette images.\n\nPass a value of 1 for blending mode, and 0 for non-blending mode.\n\n$image->saveAlpha($saveAlpha)\nBy default, GD (libgd 2.0.2 and above) does not attempt to save full alpha channel\ninformation (as opposed to single-color transparency) when saving PNG images. (PNG is\ncurrently the only output format supported by gd which can accommodate alpha channel\ninformation.) This saves space in the output file. If you wish to create an image with alpha\nchannel information for use with tools that support it, call saveAlpha(1) to turn on saving\nof such information, and call alphaBlending(0) to turn off alpha blending within the library\nso that alpha channel information is actually stored in the image rather than being\ncomposited immediately at the time that drawing functions are invoked.\n"
                },
                {
                    "name": "Miscellaneous Image Methods",
                    "content": "These are various utility methods that are useful in some circumstances.\n\n$image->interlaced([$flag])\nThis method sets or queries the image's interlaced setting. Interlace produces a cool\nvenetian blinds effect on certain viewers. Provide a true parameter to set the interlace\nattribute. Provide undef to disable it. Call the method without parameters to find out the\ncurrent setting.\n\n($width,$height) = $image->getBounds()\nThis method will return a two-member list containing the width and height of the image. You\nquery but not change the size of the image once it's created.\n\n$width = $image->width\n$height = $image->height\nReturn the width and height of the image, respectively.\n\n$istruecolor = $image->isTrueColor()\nThis method will return a Boolean representing whether the image is true color or not.\n\n$flag = $image1->compare($image2)\nCompare two images and return a bitmap describing the differences found, if any. The return\nvalue must be logically AND'ed with one or more constants in order to determine the\ndifferences. The following constants are available:\n\nGDCMPIMAGE             The two images look different\nGDCMPNUMCOLORS        The two images have different numbers of colors\nGDCMPCOLOR             The two images' palettes differ\nGDCMPSIZEX            The two images differ in the horizontal dimension\nGDCMPSIZEY            The two images differ in the vertical dimension\nGDCMPTRANSPARENT       The two images have different transparency\nGDCMPBACKGROUND        The two images have different background colors\nGDCMPINTERLACE         The two images differ in their interlace\nGDCMPTRUECOLOR         The two images are not both true color\n\nThe most important of these is GDCMPIMAGE, which will tell you whether the two images will\nlook different, ignoring differences in the order of colors in the color palette and other\ninvisible changes. The constants are not imported by default, but must be imported\nindividually or by importing the :cmp tag. Example:\n\nuse GD qw(:DEFAULT :cmp);\n# get $image1 from somewhere\n# get $image2 from somewhere\nif ($image1->compare($image2) & GDCMPIMAGE) {\nwarn \"images differ!\";\n}\n\n$image->clip($x1,$y1,$x2,$y2)\n($x1,$y1,$x2,$y2) = $image->clip\nSet or get the clipping rectangle. When the clipping rectangle is set, all drawing will be\nclipped to occur within this rectangle. The clipping rectangle is initially set to be equal\nto the boundaries of the whole image. Change it by calling clip() with the coordinates of\nthe new clipping rectangle. Calling clip() without any arguments will return the current\nclipping rectangle.\n\n$flag = $image->boundsSafe($x,$y)\nThe boundsSafe() method will return true if the point indicated by ($x,$y) is within the\nclipping rectangle, or false if it is not. If the clipping rectangle has not been set, then\nit will return true if the point lies within the image boundaries.\n"
                },
                {
                    "name": "Grouping Methods",
                    "content": "GD does not support grouping of objects, but GD::SVG does. In that subclass, the following\nmethods declare new groups of graphical objects:\n\n$image->startGroup([$id,\\%style])\n$image->endGroup()\n$group = $image->newGroup\nSee GD::SVG for information.\n"
                }
            ]
        },
        "Polygons": {
            "content": "A few primitive polygon creation and manipulation methods are provided. They aren't part of the\nGd library, but I thought they might be handy to have around (they're borrowed from my qd.pl\nQuickdraw library). Also see GD::Polyline.\n\n$poly = GD::Polygon->new\nCreate an empty polygon with no vertices.\n\n$poly = GD::Polygon->new;\n\n$poly->addPt($x,$y)\nAdd point (x,y) to the polygon.\n\n$poly->addPt(0,0);\n$poly->addPt(0,50);\n$poly->addPt(25,25);\n$myImage->fillPoly($poly,$blue);\n\n($x,$y) = $poly->getPt($index)\nRetrieve the point at the specified vertex.\n\n($x,$y) = $poly->getPt(2);\n\n$poly->setPt($index,$x,$y)\nChange the value of an already existing vertex. It is an error to set a vertex that isn't\nalready defined.\n\n$poly->setPt(2,100,100);\n\n($x,$y) = $poly->deletePt($index)\nDelete the specified vertex, returning its value.\n\n($x,$y) = $poly->deletePt(1);\n\n$poly->clear()\nDelete all vertices, restoring the polygon to its initial empty state.\n\n$poly->toPt($dx,$dy)\nDraw from current vertex to a new vertex, using relative (dx,dy) coordinates. If this is the\nfirst point, act like addPt().\n\n$poly->addPt(0,0);\n$poly->toPt(0,50);\n$poly->toPt(25,-25);\n$myImage->fillPoly($poly,$blue);\n\n$vertexcount = $poly->length\nReturn the number of vertices in the polygon.\n\n$points = $poly->length;\n\n@vertices = $poly->vertices\nReturn a list of all the vertices in the polygon object. Each member of the list is a\nreference to an (x,y) array.\n\n@vertices = $poly->vertices;\nforeach $v (@vertices)\nprint join(\",\",@$v),\"\\n\";\n}\n\n@rect = $poly->bounds\nReturn the smallest rectangle that completely encloses the polygon. The return value is an\narray containing the (left,top,right,bottom) of the rectangle.\n\n($left,$top,$right,$bottom) = $poly->bounds;\n\n$poly->offset($dx,$dy)\nOffset all the vertices of the polygon by the specified horizontal (dh) and vertical (dy)\namounts. Positive numbers move the polygon down and to the right.\n\n$poly->offset(10,30);\n\n$poly->map($srcL,$srcT,$srcR,$srcB,$destL,$dstT,$dstR,$dstB)\nMap the polygon from a source rectangle to an equivalent position in a destination rectangle,\nmoving it and resizing it as necessary. See polys.pl for an example of how this works. Both\nthe source and destination rectangles are given in (left,top,right,bottom) coordinates. For\nconvenience, you can use the polygon's own bounding box as the source rectangle.\n\n# Make the polygon really tall\n$poly->map($poly->bounds,0,0,50,200);\n\n$poly->scale($sx,$sy, [$tx,$ty])\nScale each vertex of the polygon by the X and Y factors indicated by sx and sy. For example\nscale(2,2) will make the polygon twice as large. For best results, move the center of the\npolygon to position (0,0) before you scale, then move it back to its previous position.\nAccepts an optional offset vector.\n\n$poly->transform($sx,$rx,$ry,$sy, $tx,$ty)\nRun each vertex of the polygon through a 2D affine transformation matrix, where sx and sy are\nthe X and Y scaling factors, rx and ry are the X and Y rotation factors, and tx and ty are X\nand Y offsets. See the Adobe PostScript Reference, page 154 for a full explanation, or\nexperiment.\n\nlibgd:\n\nThe transformation matrix is created using 6 numbers:\nmatrix[0] == xx\nmatrix[1] == yx\nmatrix[2] == xy\nmatrix[3] == xy (probably meaning yy here)\nmatrix[4] == x0\nmatrix[5] == y0\nwhere the transformation of a given point (x,y) is given by:\n\nxnew = xx * x + xy * y + x0;\nynew = yx * x + yy * y + y0;\n\nGD::Polyline\nPlease see GD::Polyline for information on creating open polygons and splines.\n",
            "subsections": []
        },
        "Font Utilities": {
            "content": "The libgd library (used by the Perl GD library) has built-in support for about half a dozen\nfonts, which were converted from public-domain X Windows fonts. For more fonts, compile libgd\nwith TrueType support and use the stringFT() call.\n\nIf you wish to add more built-in fonts, the directory bdfscripts contains two contributed\nutilities that may help you convert X-Windows BDF-format fonts into the format that libgd uses\ninternally. However these scripts were written for earlier versions of GD which included its own\nmini-gd library. These scripts will have to be adapted for use with libgd, and the libgd library\nitself will have to be recompiled and linked! Please do not contact me for help with these\nscripts: they are unsupported.\n\nEach of these fonts is available both as an imported global (e.g. gdSmallFont) and as a package\nmethod (e.g. GD::Font->Small).\n\ngdSmallFont\nGD::Font->Small\nThis is the basic small font, \"borrowed\" from a well known public domain 6x12 font.\n\ngdLargeFont\nGD::Font->Large\nThis is the basic large font, \"borrowed\" from a well known public domain 8x16 font.\n\ngdMediumBoldFont\nGD::Font->MediumBold\nThis is a bold font intermediate in size between the small and large fonts, borrowed from a\npublic domain 7x13 font;\n\ngdTinyFont\nGD::Font->Tiny\nThis is a tiny, almost unreadable font, 5x8 pixels wide.\n\ngdGiantFont\nGD::Font->Giant\nThis is a 9x15 bold font converted by Jan Pazdziora from a sans serif X11 font.\n\n$font->nchars\nThis returns the number of characters in the font.\n\nprint \"The large font contains \",gdLargeFont->nchars,\" characters\\n\";\n\n$font->offset\nThis returns the ASCII value of the first character in the font\n\n$width = $font->width\n$height = $font->height\n\"height\"\nThese return the width and height of the font.\n\n($w,$h) = (gdLargeFont->width,gdLargeFont->height);\n",
            "subsections": []
        },
        "Helper Functions": {
            "content": "GD::LIBGDVERSION\nReturns a number of the libgd VERSION, like 2.0204, 2.0033 or 2.01.\n\nGD::VERSIONSTRING\nReturns the string of the libgd VERSION, like \"2.2.4\".\n\nGD::constant\n",
            "subsections": []
        },
        "Obtaining the C-language version of gd": {
            "content": "libgd, the C-language version of gd, can be obtained at URL http://libgd.org/ Directions for\ninstalling and using it can be found at that site. Please do not contact me for help with libgd.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "The GD.pm interface is copyright 1995-2010, Lincoln D. Stein. This package and its accompanying\nlibraries is free software; you can redistribute it and/or modify it under the terms of the GPL\n(either version 1, or at your option, any later version) or the Artistic License 2.0. Refer to\nLICENSE for the full license text. package for details.\n\nThe latest versions of GD.pm are available at\n\nhttps://github.com/lstein/Perl-GD\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "GD::Polyline, GD::SVG, GD::Simple, Image::Magick\n",
            "subsections": []
        }
    },
    "summary": "GD.pm - Interface to Gd Graphics Library",
    "flags": [],
    "examples": [],
    "see_also": []
}