Drawing Lines, Rectangles, and Polygons with PHP

The first parameter is the canvas to draw on. The next set of parameters are the x and y coordinates to specify where GD should draw the shape. In ImageLine( ), the four coordinates are the endpoints of the line, and in ImageRectangle( ), they’re the opposite corners of the rectangle. For example, ImageLine($image, 0, 0, 100, 100, $color) produces a diagonal line. Passing the same parameters to ImageRectangle( ) produces a rectangle with corners at (0,0), (100,0), (0,100), and (100,100).

Draw a line by using ImageLine():

ImageLine($image, $x1, $y1, $x2, $y2, $color);

Draw an open rectangle by using ImageRectangle( ):

ImageRectangle($image, $x1, $y1, $x2, $y2, $color);

Draw a solid rectangle by using ImageFilledRectangle( ):

ImageFilledRectangle($image, $x1, $y1, $x2, $y2, $color);

Draw an open polygon by using ImagePolygon( ):

$points = array($x1, $y1, $x2, $y2, $x3, $y3);
ImagePolygon($image, $points, count($points)/2, $color);

Draw a filled polygon by using ImageFilledPolygon( ):

$points = array($x1, $y1, $x2, $y2, $x3, $y3);
ImageFilledPolygon($image, $points, count($points)/2, $color);
Share Article/Example:
  • DotNetKicks
  • DZone
  • StumbleUpon
  • Print
  • Add to favorites
  • Digg
  • del.icio.us
  • Twitter
  • Facebook
  • LinkedIn
  • Posterous
  • Slashdot

 

 
eXTReMe Tracker