PHP | imagepolygon() Function
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, $points, $num_points, $color )
Parameters: This function accepts four parameters as mentioned above and described below:
- $image: The imagecreatetruecolor() function is used to create a blank image in a given size.
- $points: This parameter is used to hold the consecutive vertices of polygon.
- $num_points: This parameter contains total number of vertices in a polygon. It must be greater than 3, because minimum three vertices required to create a polygon.
- $color: This variable contains the filled color identifier. A color identifier created with imagecolorallocate() function.
Return Value: This function returns TRUE on success or FALSE on failure.
Below programs illustrate the imagepolygon() function in PHP.
Program 1:
php
<?php
$values = array (
150, 50,
50, 250,
250, 250
);
$image = imagecreatetruecolor(300, 300);
$background_color = imagecolorallocate( $image , 0, 153, 0);
imagefill( $image , 0, 0, $background_color );
$image_color = imagecolorallocate( $image , 255, 255, 255);
imagepolygon( $image , $values , 3, $image_color );
header( 'Content-type: image/png' );
imagepng( $image );
?>
|
Output:
Program 2:
php
<?php
$values = array (
150, 50,
55, 119,
91, 231,
209, 231,
245, 119
);
$image = imagecreatetruecolor(300, 300);
$background_color = imagecolorallocate( $image , 0, 153, 0);
imagefill( $image , 0, 0, $background_color );
$col_poly = imagecolorallocate( $image , 255, 255, 255);
imagepolygon( $image , $values , 5, $col_poly );
header( 'Content-type: image/png' );
imagepng( $image );
?>
|
Output:
Related Articles:
Reference: http://php.net/manual/en/function.imagepolygon.php
Last Updated :
15 Dec, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...