O'Reilly logo

Programming Web Graphics with Perl and GNU Softwar by Shawn Wallace

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required