{
    "content": [
        {
            "type": "text",
            "text": "# GD::Simple (perldoc)\n\n## NAME\n\nGD::Simple - Simplified interface to GD library\n\n## SYNOPSIS\n\nFor a nice tutorial on using this module, see Gabor Szabo's article at\nhttp://perlmaven.com/drawing-images-using-gd-simple.\nuse GD::Simple;\n# create a new image\n$img = GD::Simple->new(400,250);\n# draw a red rectangle with blue borders\n$img->bgcolor('red');\n$img->fgcolor('blue');\n$img->rectangle(10,10,50,50);\n# draw an empty rectangle with green borders\n$img->bgcolor(undef);\n$img->fgcolor('green');\n$img->rectangle(30,30,100,100);\n# move to (80,80) and draw a green line to (100,190)\n$img->moveTo(80,80);\n$img->lineTo(100,190);\n# draw a solid orange ellipse\n$img->moveTo(110,100);\n$img->bgcolor('orange');\n$img->fgcolor('orange');\n$img->ellipse(40,40);\n# draw a black filled arc\n$img->moveTo(150,150);\n$img->fgcolor('black');\n$img->arc(50,50,0,100,gdNoFill|gdEdged);\n# draw a string at (10,180) using the default\n# built-in font\n$img->moveTo(10,180);\n$img->string('This is very simple');\n# draw a string at (280,210) using 20 point\n# times italic, angled upward 90 degrees\n$img->moveTo(280,210);\n$img->font('Times:italic');\n$img->fontsize(20);\n$img->angle(-90);\n$img->string('This is very fancy');\n# some turtle graphics\n$img->moveTo(300,100);\n$img->penSize(3,3);\n$img->angle(0);\n$img->line(20);   # 20 pixels going to the right\n$img->turn(30);   # set turning angle to 30 degrees\n$img->line(20);   # 20 pixel line\n$img->line(20);\n$img->line(20);\n$img->turn(-90); # set turning angle to -90 degrees\n$img->line(50);  # 50 pixel line\n# draw a cyan polygon edged in blue\nmy $poly = GD::Polygon->new;\n$poly->addPt(150,100);\n$poly->addPt(199,199);\n$poly->addPt(100,199);\n$img->bgcolor('cyan');\n$img->fgcolor('blue');\n$img->penSize(1,1);\n$img->polygon($poly);\n# convert into png data\nprint $img->png;\n\n## DESCRIPTION\n\nGD::Simple is a subclass of the GD library that shortens many of the long GD method calls by\nstoring information about the pen color, size and position in the GD object itself. It also adds\na small number of \"turtle graphics\" style calls for those who prefer to work in polar\ncoordinates. In addition, the library allows you to use symbolic names for colors, such as\n\"chartreuse\", and will manage the colors for you.\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION** (2 subsections)\n- **COLORS**\n- **AUTHOR**\n- **SEE ALSO**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "GD::Simple",
        "section": "",
        "mode": "perldoc",
        "summary": "GD::Simple - Simplified interface to GD library",
        "synopsis": "For a nice tutorial on using this module, see Gabor Szabo's article at\nhttp://perlmaven.com/drawing-images-using-gd-simple.\nuse GD::Simple;\n# create a new image\n$img = GD::Simple->new(400,250);\n# draw a red rectangle with blue borders\n$img->bgcolor('red');\n$img->fgcolor('blue');\n$img->rectangle(10,10,50,50);\n# draw an empty rectangle with green borders\n$img->bgcolor(undef);\n$img->fgcolor('green');\n$img->rectangle(30,30,100,100);\n# move to (80,80) and draw a green line to (100,190)\n$img->moveTo(80,80);\n$img->lineTo(100,190);\n# draw a solid orange ellipse\n$img->moveTo(110,100);\n$img->bgcolor('orange');\n$img->fgcolor('orange');\n$img->ellipse(40,40);\n# draw a black filled arc\n$img->moveTo(150,150);\n$img->fgcolor('black');\n$img->arc(50,50,0,100,gdNoFill|gdEdged);\n# draw a string at (10,180) using the default\n# built-in font\n$img->moveTo(10,180);\n$img->string('This is very simple');\n# draw a string at (280,210) using 20 point\n# times italic, angled upward 90 degrees\n$img->moveTo(280,210);\n$img->font('Times:italic');\n$img->fontsize(20);\n$img->angle(-90);\n$img->string('This is very fancy');\n# some turtle graphics\n$img->moveTo(300,100);\n$img->penSize(3,3);\n$img->angle(0);\n$img->line(20);   # 20 pixels going to the right\n$img->turn(30);   # set turning angle to 30 degrees\n$img->line(20);   # 20 pixel line\n$img->line(20);\n$img->line(20);\n$img->turn(-90); # set turning angle to -90 degrees\n$img->line(50);  # 50 pixel line\n# draw a cyan polygon edged in blue\nmy $poly = GD::Polygon->new;\n$poly->addPt(150,100);\n$poly->addPt(199,199);\n$poly->addPt(100,199);\n$img->bgcolor('cyan');\n$img->fgcolor('blue');\n$img->penSize(1,1);\n$img->polygon($poly);\n# convert into png data\nprint $img->png;",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 71,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 6,
                "subsections": [
                    {
                        "name": "The Pen",
                        "lines": 34
                    },
                    {
                        "name": "Methods",
                        "lines": 205
                    }
                ]
            },
            {
                "name": "COLORS",
                "lines": 36,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 6,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 2,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "GD::Simple - Simplified interface to GD library\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "For a nice tutorial on using this module, see Gabor Szabo's article at\nhttp://perlmaven.com/drawing-images-using-gd-simple.\n\nuse GD::Simple;\n\n# create a new image\n$img = GD::Simple->new(400,250);\n\n# draw a red rectangle with blue borders\n$img->bgcolor('red');\n$img->fgcolor('blue');\n$img->rectangle(10,10,50,50);\n\n# draw an empty rectangle with green borders\n$img->bgcolor(undef);\n$img->fgcolor('green');\n$img->rectangle(30,30,100,100);\n\n# move to (80,80) and draw a green line to (100,190)\n$img->moveTo(80,80);\n$img->lineTo(100,190);\n\n# draw a solid orange ellipse\n$img->moveTo(110,100);\n$img->bgcolor('orange');\n$img->fgcolor('orange');\n$img->ellipse(40,40);\n\n# draw a black filled arc\n$img->moveTo(150,150);\n$img->fgcolor('black');\n$img->arc(50,50,0,100,gdNoFill|gdEdged);\n\n# draw a string at (10,180) using the default\n# built-in font\n$img->moveTo(10,180);\n$img->string('This is very simple');\n\n# draw a string at (280,210) using 20 point\n# times italic, angled upward 90 degrees\n$img->moveTo(280,210);\n$img->font('Times:italic');\n$img->fontsize(20);\n$img->angle(-90);\n$img->string('This is very fancy');\n\n# some turtle graphics\n$img->moveTo(300,100);\n$img->penSize(3,3);\n$img->angle(0);\n$img->line(20);   # 20 pixels going to the right\n$img->turn(30);   # set turning angle to 30 degrees\n$img->line(20);   # 20 pixel line\n$img->line(20);\n$img->line(20);\n$img->turn(-90); # set turning angle to -90 degrees\n$img->line(50);  # 50 pixel line\n\n# draw a cyan polygon edged in blue\nmy $poly = GD::Polygon->new;\n$poly->addPt(150,100);\n$poly->addPt(199,199);\n$poly->addPt(100,199);\n$img->bgcolor('cyan');\n$img->fgcolor('blue');\n$img->penSize(1,1);\n$img->polygon($poly);\n\n# convert into png data\nprint $img->png;\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "GD::Simple is a subclass of the GD library that shortens many of the long GD method calls by\nstoring information about the pen color, size and position in the GD object itself. It also adds\na small number of \"turtle graphics\" style calls for those who prefer to work in polar\ncoordinates. In addition, the library allows you to use symbolic names for colors, such as\n\"chartreuse\", and will manage the colors for you.\n",
                "subsections": [
                    {
                        "name": "The Pen",
                        "content": "GD::Simple maintains a \"pen\" whose settings are used for line- and shape-drawing operations. The\npen has the following properties:\n\nfgcolor\nThe pen foreground color is the color of lines and the borders of filled and unfilled\nshapes.\n\nbgcolor\nThe pen background color is the color of the contents of filled shapes.\n\npensize\nThe pen size is the width of the pen. Larger sizes draw thicker lines.\n\nposition\nThe pen position is its current position on the canvas in (X,Y) coordinates.\n\nangle\nWhen drawing in turtle mode, the pen angle determines the current direction of lines of\nrelative length.\n\nturn\nWhen drawing in turtle mode, the turn determines the clockwise or counterclockwise angle\nthat the pen will turn before drawing the next line.\n\nfont\nThe font to use when drawing text. Both built-in bitmapped fonts and TrueType fonts are\nsupported.\n\nfontsize\nThe size of the font to use when drawing with TrueType fonts.\n\nOne sets the position and properties of the pen and then draws. As the drawing progresses, the\nposition of the pen is updated.\n"
                    },
                    {
                        "name": "Methods",
                        "content": "GD::Simple introduces a number of new methods, a few of which have the same name as GD::Image\nmethods, and hence change their behavior. In addition to these new methods, GD::Simple objects\nsupport all of the GD::Image methods. If you make a method call that isn't directly supported by\nGD::Simple, it refers the request to the underlying GD::Image object. Hence one can load a JPEG\nimage into GD::Simple and declare it to be TrueColor by using this call, which is effectively\ninherited from GD::Image:\n\nmy $img = GD::Simple->newFromJpeg('./myimage.jpg',1);\n\nThe rest of this section describes GD::Simple-specific methods.\n\n$img = GD::Simple->new($x,$y [,$truecolor])\n$img = GD::Simple->new($gd)\nCreate a new GD::Simple object. There are two forms of new(). In the first form, pass the\nwidth and height of the desired canvas, and optionally a boolean flag to request a truecolor\nimage. In the second form, pass a previously-created GD::Image object.\n\nGD::Simple->class('GD');\nGD::Simple->class('GD::SVG');\nSelect whether new() should use GD or GD::SVG internally. Call GD::Simple->class('GD::SVG')\nbefore calling new() if you wish to generate SVG images.\n\nIf future GD subclasses are created, this method will subport them.\n\n$img->moveTo($x,$y)\nThis call changes the position of the pen without drawing. It moves the pen to position\n($x,$y) on the drawing canvas.\n\n$img->move($dx,$dy)\n$img->move($dr)\nThis call changes the position of the pen without drawing. When called with two arguments it\nmoves the pen $dx pixels to the right and $dy pixels downward. When called with one argument\nit moves the pen $dr pixels along the vector described by the current pen angle.\n\n$img->lineTo($x,$y)\nThe lineTo() call simultaneously draws and moves the pen. It draws a line from the current\npen position to the position defined by ($x,$y) using the current pen size and color. After\ndrawing, the position of the pen is updated to the new position.\n\n$img->line($x1,$y1,$x2,$y2 [,$color])\n$img->line($dx,$dy)\n$img->line($dr)\nThe line() call simultaneously draws and moves the pen. When called with two arguments it\ndraws a line from the current position of the pen to the position $dx pixels to the right\nand $dy pixels down. When called with one argument, it draws a line $dr pixels long along\nthe angle defined by the current pen angle.\n\nWhen called with four or five arguments, line() behaves like GD::Image->line().\n\n$img->clear\nThis method clears the canvas by painting over it with the current background color.\n\n$img->rectangle($x1,$y1,$x2,$y2)\nThis method draws the rectangle defined by corners ($x1,$y1), ($x2,$y2). The rectangle's\nedges are drawn in the foreground color and its contents are filled with the background\ncolor. To draw a solid rectangle set bgcolor equal to fgcolor. To draw an unfilled rectangle\n(transparent inside), set bgcolor to undef.\n\n$img->ellipse($width,$height)\nThis method draws the ellipse centered at the current location with width $width and height\n$height. The ellipse's border is drawn in the foreground color and its contents are filled\nwith the background color. To draw a solid ellipse set bgcolor equal to fgcolor. To draw an\nunfilled ellipse (transparent inside), set bgcolor to undef.\n\n$img->arc([$cx,$cy,] $width,$height,$start,$end [,$style])\nThis method draws filled and unfilled arcs, at the current position, with the current fore-\nand background colors. See GD for a description of the arguments. To draw a solid arc (such\nas a pie wedge) set bgcolor equal to fgcolor. To draw an unfilled arc, set bgcolor to undef.\n\n$img->polygon($poly)\nThis method draws filled and unfilled polygon using the current settings of fgcolor for the\npolygon border and bgcolor for the polygon fill color. See GD for a description of creating\npolygons. To draw a solid polygon set bgcolor equal to fgcolor. To draw an unfilled polygon,\nset bgcolor to undef.\n\n$img->polyline($poly)\nThis method draws polygons without closing the first and last vertices (similar to\nGD::Image->unclosedPolygon()). It uses the fgcolor to draw the line.\n\n$img->string($string)\nThis method draws the indicated string starting at the current position of the pen. The pen\nis moved to the end of the drawn string. Depending on the font selected with the font()\nmethod, this will use either a bitmapped GD font or a TrueType font. The angle of the pen\nwill be consulted when drawing the text. For TrueType fonts, any angle is accepted. For GD\nbitmapped fonts, the angle can be either 0 (draw horizontal) or -90 (draw upwards).\n\nFor consistency between the TrueType and GD font behavior, the string is always drawn so\nthat the current position of the pen corresponds to the bottom left of the first character\nof the text. This is different from the GD behavior, in which the first character of\nbitmapped fonts hangs down from the pen point.\n\nThis method returns a polygon indicating the bounding box of the rendered text. If an error\noccurred (such as invalid font specification) it returns undef and an error message in $@.\n\n$metrics = $img->fontMetrics\n($metrics,$width,$height) = GD::Simple->fontMetrics($font,$fontsize,$string)\nThis method returns information about the current font, most commonly a TrueType font. It\ncan be invoked as an instance method (on a previously-created GD::Simple object) or as a\nclass method (on the 'GD::Simple' class).\n\nWhen called as an instance method, fontMetrics() takes no arguments and returns a single\nhash reference containing the metrics that describe the currently selected font and size.\nThe hash reference contains the following information:\n\nxheight      the base height of the font from the bottom to the top of\na lowercase 'm'\n\nascent       the length of the upper stem of the lowercase 'd'\n\ndescent      the length of the lower step of the lowercase 'j'\n\nlineheight   the distance from the bottom of the 'j' to the top of\nthe 'd'\n\nleading      the distance between two adjacent lines\n\nThis description and code was changed with 2.75.\n\n($deltax,$deltay)= $img->stringBounds($string)\nThis method indicates the X and Y offsets (which may be negative) that will occur when the\ngiven string is drawn using the current font, fontsize and angle. When the string is drawn\nhorizontally, it gives the width and height of the string's bounding box.\n\n$deltax = $img->stringWidth($string)\nThis method indicates the width of the string given the current font, fontsize and angle. It\nis the same as ($img->stringBounds($string))[0]\n\n($x,$y) = $img->curPos\nReturn the current position of the pen. Set the current position using moveTo().\n\n$font = $img->font([$newfont] [,$newsize])\nGet or set the current font. Fonts can be GD::Font objects, TrueType font file paths, or\nfontconfig font patterns like \"Times:italic\" (see fontconfig). The latter feature requires\nthat you have the fontconfig library installed and are using libgd version 2.0.33 or higher.\n\nAs a shortcut, you may pass two arguments to set the font and the fontsize simultaneously.\nThe fontsize is only valid when drawing with TrueType fonts.\n\n$size = $img->fontsize([$newfontsize])\nGet or set the current font size. This is only valid for TrueType fonts.\n\n$size = $img->penSize([$newpensize])\nGet or set the current pen width for use during line drawing operations.\n\n$angle = $img->angle([$newangle])\nSet the current angle for use when calling line() or move() with a single argument.\n\nHere is an example of using turn() and angle() together to draw an octagon. The first line\ndrawn is the downward-slanting top right edge. The last line drawn is the horizontal top of\nthe octagon.\n\n$img->moveTo(200,50);\n$img->angle(0);\n$img->turn(360/8);\nfor (1..8) { $img->line(50) }\n\n$angle = $img->turn([$newangle])\nGet or set the current angle to turn prior to drawing lines. This value is only used when\ncalling line() or move() with a single argument. The turning angle will be applied to each\ncall to line() or move() just before the actual drawing occurs.\n\nAngles are in degrees. Positive values turn the angle clockwise.\n\n$color = $img->fgcolor([$newcolor])\nGet or set the pen's foreground color. The current pen color can be set by (1) using an\n(r,g,b) triple; (2) using a previously-allocated color from the GD palette; or (3) by using\na symbolic color name such as \"chartreuse.\" The list of color names can be obtained using\ncolornames(). The special color name 'transparent' will create a completely transparent\ncolor.\n\n$color = $img->bgcolor([$newcolor])\nGet or set the pen's background color. The current pen color can be set by (1) using an\n(r,g,b) triple; (2) using a previously-allocated color from the GD palette; or (3) by using\na symbolic color name such as \"chartreuse.\" The list of color names can be obtained using\ncolornames(). The special color name 'transparent' will create a completely transparent\ncolor.\n\n$index = $img->translatecolor(@args)\nTranslates a color into a GD palette or TrueColor index. You may pass either an (r,g,b)\ntriple or a symbolic color name. If you pass a previously-allocated index, the method will\nreturn it unchanged.\n\n$index = $img->alphaColor(@args,$alpha)\nCreates an alpha color. You may pass either an (r,g,b) triple or a symbolic color name,\nfollowed by an integer indicating its opacity. The opacity value ranges from 0 (fully\nopaque) to 127 (fully transparent).\n\n@names = GD::Simple->colornames\n$translatetable = GD::Simple->colornames\nCalled in a list context, colornames() returns the list of symbolic color names recognized\nby this module. Called in a scalar context, the method returns a hash reference in which the\nkeys are the color names and the values are array references containing [r,g,b] triples.\n\n$gd = $img->gd\nReturn the internal GD::Image object. Usually you will not need to call this since all GD\nmethods are automatically referred to this object.\n\n($red,$green,$blue) = GD::Simple->HSVtoRGB($hue,$saturation,$value)\nConvert a Hue/Saturation/Value (HSV) color into an RGB triple. The hue, saturation and value\nare integers from 0 to 255.\n\n($hue,$saturation,$value) = GD::Simple->RGBtoHSV($red,$green,$blue)\nConvert a Red/Green/Blue (RGB) value into a Hue/Saturation/Value (HSV) triple. The hue,\nsaturation and value are integers from 0 to 255.\n"
                    }
                ]
            },
            "COLORS": {
                "content": "This script will create an image showing all the symbolic colors.\n\n#!/usr/bin/perl\n\nuse strict;\nuse GD::Simple;\n\nmy @colornames = GD::Simple->colornames;\nmy $cols = int(sqrt(@colornames));\nmy $rows = int(@colornames/$cols)+1;\n\nmy $cellwidth    = 100;\nmy $cellheight   = 50;\nmy $legendheight = 16;\nmy $width       = $cols * $cellwidth;\nmy $height      = $rows * $cellheight;\n\nmy $img = GD::Simple->new($width,$height);\n$img->font(gdSmallFont);\n\nfor (my $c=0; $c<$cols; $c++) {\nfor (my $r=0; $r<$rows; $r++) {\nmy $color = $colornames[$c*$rows + $r] or next;\nmy @topleft  = ($c*$cellwidth,$r*$cellheight);\nmy @botright = ($topleft[0]+$cellwidth,$topleft[1]+$cellheight-$legendheight);\n$img->bgcolor($color);\n$img->fgcolor($color);\n$img->rectangle(@topleft,@botright);\n$img->moveTo($topleft[0]+2,$botright[1]+$legendheight-2);\n$img->fgcolor('black');\n$img->string($color);\n}\n}\n\nprint $img->png;\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "The GD::Simple module is copyright 2004, Lincoln D. Stein. It is distributed under the same\nterms as Perl itself. See the \"Artistic License\" in the Perl source code distribution for\nlicensing terms.\n\nThe latest versions of GD.pm are available at https://github.com/lstein/Perl-GD\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "GD, GD::Polyline, GD::SVG, Image::Magick\n",
                "subsections": []
            }
        }
    }
}