PHP | imagepolygon() Function (original) (raw)

Last Updated : 11 Jul, 2025

The imagepolygon() function is an inbuilt function in PHP which is used to draw a polygon. This function returns TRUE on success and returns FALSE otherwise.
Syntax:

bool imagepolygon( image,image, image,points, numpoints,num_points, numpoints,color )

Parameters: This function accepts four parameters as mentioned above and described below:

Return Value: This function returns TRUE on success or FALSE on failure.
Below programs illustrate the imagepolygon() function in PHP.
Program 1:

php `

backgroundcolor=imagecolorallocate(background_color = imagecolorallocate(backgroundcolor=imagecolorallocate(image, 0, 153, 0); // Fill background with above selected color imagefill($image, 0, 0, $background_color); // Allocate a color for the polygon imagecolor=imagecolorallocate(image_color = imagecolorallocate(imagecolor=imagecolorallocate(image, 255, 255, 255); // Draw the polygon imagepolygon($image, values,3,values, 3, values,3,image_color); // Output the picture to the browser header('Content-type: image/png'); imagepng($image); ?>

`

Output:

img polygon

Program 2:

php `

backgroundcolor=imagecolorallocate(background_color = imagecolorallocate(backgroundcolor=imagecolorallocate(image, 0, 153, 0); // Fill background with above selected color imagefill($image, 0, 0, $background_color); // Allocate a color for the polygon colpoly=imagecolorallocate(col_poly = imagecolorallocate(colpoly=imagecolorallocate(image, 255, 255, 255); // Draw the polygon imagepolygon($image, values,5,values, 5, values,5,col_poly); // Output the picture to the browser header('Content-type: image/png'); imagepng($image); ?>

`

Output:

img polygon

Related Articles:

Reference: https://www.php.net/manual/en/function.imagepolygon.php