The imageopenpolygon() function is an inbuilt function in PHP which is used to draws an open polygon.
Syntax:
bool imageopenpolygon( resource $image, array $points, int $num_points, int $color )
Parameters: This function accepts four parameters as mentioned above and described below:
- $image: It specifies the image resource to work on.
- $points: It specifies the points of polygon.
- $num_points: It specifies the number of points.
- $color: It specifies the color of polygon.
Return Value: This function returns TRUE on success or FALSE on failure.
Below examples illustrate the imageopenpolygon() function in PHP:
Example 1: In this example, we will draw polygon on a blank drawing.
<?php // Create a blank image $image = imagecreatetruecolor(400, 300); // Prepare the colors $red = imagecolorallocate( $image , 255, 0, 0); // Points of array $points = array ( 80, 150, 150, 250, 300, 250, 370, 150, 230, 50, 80, 150 ); // Create an polygon imageopenpolygon( $image , $points , 6, $red ); // Output to browser header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); ?> |
Output:
Example 2: In this example, drawing polygon on a image.
<?php // Create an image instance $image = imagecreatefrompng( // Prepare the colors $red = imagecolorallocate( $image , 255, 0, 0); // Points of array $points = array ( 10, 10, 660, 10, 660, 100, 10, 100, 10, 10 ); // Create an polygon imageopenpolygon( $image , $points , 5, $red ); // Output to browser header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); ?> |
Output:
Reference: https://www.php.net/manual/en/function.imageopenpolygon.php