Drawing a Polygon

You can draw more sophisticated shapes using imagepolygon(). This function requires an image resource, an array of point coordinates, an integer representing the number of points in the shape, and a color resource. The array passed to imagepolygon() should be numerically indexed. The first two elements give the coordinates of the first point, the second two give the coordinates of the second point, and so on. imagepolygon() fills in the lines between the points, automatically closing your shape by joining the final point to the first. You can create a filled polygon with the imagefilledpolygon() function.

Listing 15.6 draws a filled polygon, outputting the result to the browser.

Listing 15.6. Drawing a Polygon with imagefilledpolygon() ...

Get Sams Teach Yourself PHP in 24 Hours, Third Edition 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.