PHP | imagefilledpolygon() Function
Last Updated :
03 May, 2023
The imagefilledpolygon() function is an inbuilt function in PHP which is used to draw a filled polygon. This function Returns TRUE on success and returns FALSE otherwise.
Syntax:
bool imagefilledpolygon( $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 the polygon.
- $num_points: This parameter contains the total number of vertices in a polygon. It must be greater than 3 because a minimum of three vertices is required to create a polygon.
- $color: This variable contains the filled color identifier. A color identifier was created with imagecolorallocate() function.
Return Value: This function returns TRUE on success or FALSE on failure.
The below programs illustrate the imagefilledpolygon() function in PHP.
Program 1:
php
<?php
$values = array (
150, 50,
50, 250,
250, 250
);
$image = imagecreatetruecolor(300, 300);
$bg = imagecolorallocate( $image , 255, 255, 255);
$gr = imagecolorallocate( $image , 0, 153, 0);
imagefilledrectangle( $image , 0, 0, 300, 300, $bg );
imagefilledpolygon( $image , $values , 3, $gr );
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);
$bg = imagecolorallocate( $image , 255, 255, 255);
$blue = imagecolorallocate( $image , 0, 153, 0);
imagefilledrectangle( $image , 0, 0, 300, 300, $bg );
imagefilledpolygon( $image , $values , 5, $blue );
header( 'Content-type: image/png' );
imagepng( $image );
imagedestroy( $image );
?>
|
Output:
Related Articles:
Reference: http://php.net/manual/en/function.imagefilledpolygon.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...