PHP | imageopenpolygon() Function
Last Updated :
31 Jan, 2020
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
$image = imagecreatetruecolor(400, 300);
$red = imagecolorallocate( $image , 255, 0, 0);
$points = array (
80, 150,
150, 250,
300, 250,
370, 150,
230, 50,
80, 150
);
imageopenpolygon( $image , $points , 6, $red );
header( 'Content-type: image/png' );
imagepng( $image );
imagedestroy( $image );
?>
|
Output:
Example 2: In this example, drawing polygon on a image.
<?php
$image = imagecreatefrompng(
$red = imagecolorallocate( $image , 255, 0, 0);
$points = array (
10, 10,
660, 10,
660, 100,
10, 100,
10, 10
);
imageopenpolygon( $image , $points , 5, $red );
header( 'Content-type: image/png' );
imagepng( $image );
imagedestroy( $image );
?>
|
Output:
Reference: https://www.php.net/manual/en/function.imageopenpolygon.php
Share your thoughts in the comments
Please Login to comment...