TechniqueUse the ImagePolygon() and the ImageFilledPolygon() functions to draw polygons. Example 1 ”A simple polygon (not filled): <?php header("Content-type: image/gif"); $im = ImageCreate(100, 20); $white = ImageColorAllocate($im, 255, 255, 255); $light_blue = ImageColorAllocate($im, 20, 93, 233); $points = array(12, 10, 15, 20, 50, 17, 70, 10); ImagePolygon($im, $points, 4, $light_blue); ImageGif($im); ImageDestroy($im); ?> Example 2 ”A simple, filled polygon: <?php header("Content-type: image/gif"); $im = ImageCreate(100, 20); $white = ImageColorAllocate($im, 255, 255, 255); $light_blue = ImageColorAllocate($im, 20, 93, 233); $points = array(12, 10, 15, 20, 50, 17, 70, 10); ImageFilledPolygon($im, $points, 4, $light_blue); ImageGif($im); ImageDestroy($im); ?> CommentsIn example 1, we draw a polygon on the image stream, $im , with vertices of (12, 10), (15, 20), (50, 17), and (70, 10) with a border color of light blue. We achieve this by using the ImagePolygon() function which takes an image stream, $im , as its first argument. Its second argument is an array of points (in pairs), followed by the number of vertices there are to be on the polygon, and then finally the color to draw the border of the polygon. In the example 2, we draw the same polygon as in example 1, but this time we use the ImageFilledPolygon() function which fills in the polygon with the color given by the last argument. The argument order and content are the same for both ImagePolygon() and ImageFilledPolygon() . |