Friday, September 10th, 2010

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

Tags: ,

Readers Comments (1)

  1. [...] This post was mentioned on Twitter by TutEngine.com. TutEngine.com said: Drawing Lines, Rectangles, and Polygons with PHP http://bit.ly/dztxAk #php [...]




Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.


Latest Additions

Popular User Submitted Links

1


Hosted & Optimized JS Libraries – Cached Commons

1


Multi-File Uploader & Resizer – Agile Uploader

1


Open source online notebook-to-do-list manager

1


3 tier app design in silverlight using azure & RIA services

1


Polymaps – A JS Library For Image & Vector-Tiled Maps

eXTReMe Tracker