PHP | imagefilledpolygon() Function
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 polygon.
- $num_points: This parameter contains total number of vertices in a polgon. It must be greater then 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 imagefilledpolygon() function in PHP.
Program 1:
<?php // Set the vertices of polygon $values = array ( 150, 50, // Point 1 (x, y) 50, 250, // Point 2 (x, y) 250, 250 // Point 3 (x, y) ); // It create the size of image or blank image. $image = imagecreatetruecolor(300, 300); // Set image background color $bg = imagecolorallocate( $image , 255, 255, 255); // Set image color $gr = imagecolorallocate( $image , 0, 153, 0); // fill the background imagefilledrectangle( $image , 0, 0, 300, 300, $bg ); // Draw the polygon imagefilledpolygon( $image , $values , 3, $gr ); // Output of the image. header( 'Content-type: image/png' ); imagepng( $image ); ?> |
Output:
Program 2:
<?php // Set the vertices of polygon $values = array ( 150, 50, // Point 1 (x, y) 55, 119, // Point 2 (x, y) 91, 231, // Point 3 (x, y) 209, 231, // Point 4 (x, y) 245, 119 // Point 5 (x, y) ); // It create the size of image or blank image. $image = imagecreatetruecolor(300, 300); // Set image background color $bg = imagecolorallocate( $image , 255, 255, 255); // Set image color $blue = imagecolorallocate( $image , 0, 153, 0); // fill the background imagefilledrectangle( $image , 0, 0, 300, 300, $bg ); // Draw the polygon imagefilledpolygon( $image , $values , 5, $blue ); // Output of the image. header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); ?> |
Output:
Related Articles:
Reference: http://php.net/manual/en/function.imagefilledpolygon.php
Recommended Posts:
- PHP | imagecreatetruecolor() Function
- PHP | Ds\Sequence last() Function
- PHP | array_udiff_uassoc() Function
- PHP | geoip_continent_code_by_name() Function
- PHP | opendir() Function
- PHP | cal_to_jd() Function
- PHP | stream_get_transports() Function
- PHP | Ds\Deque pop() Function
- PHP | is_numeric() Function
- PHP | Imagick adaptiveSharpenImage() Function
- PHP | ctype_print() Function
- PHP | Imagick flopImage() Function
- PHP | imagechar() Function
- PHP | array_map() Function
- PHP | cal_from_jd() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.