Name

Draw( ) — annotate an image with graphic primitives

Synopsis

$image->Draw(primitive=>{Point, Line, Rectangle, FillRectangle, Circle,
                               FillCircle, Polygon, FillPolygon, Color, Matte,
                               Text, Image, @filename},
                points=>string,
                method={Point, Replace, Floodfill, Reset},
                pen=>color,
                linewidth=>integer
                server=>servername)

The Draw( ) method allows you to draw anywhere on an image with one of many graphics primitives. An example is shown in Chapter 5. The points parameter indicates the position to start drawing and must be a string of one or more coordinates, depending on the primitive being used. A coordinate string can look like any of these:

"3,5"                       # a single point
"10,10 20,20"               # two coordinates for a line, rectangle or circle
"40,40 80,80 50,80 90,40"   # four points for a polygon

Choose one of the following primitive types:

Point

Draws a point at the single specified coordinate.

Color

Use Color to change the color of a pixel or area of pixels. This primitive takes a single coordinate for points, a color for pen, and one of the following methods:

  • Point: Re-colors the pixel with the pen color

  • Replace: Re-colors any pixel that matches the color of the pixel at given coordinate with the pen color

  • Floodfill: Re-colors any pixel that matches the color of the pixel and is a neighbor of the given coordinate. This can be thought of as the Paintbucket method.

  • Reset: Re-colors all the pixels in the image with the pen color

Figure 5-5. $image->Draw(primitive=>'Color', points=>’55,50', method=>'Floodfill', ...

Get Programming Web Graphics with Perl and GNU Softwar now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.