PHP imagepolygon() function
In this chapter you will learn:
- What is PHP imagepolygon() function
- Syntax for PHP imagepolygon() function
- Parameter for PHP imagepolygon() function
- Point Format
- Return value for PHP imagepolygon() function
- Example - PHP imagepolygon() function
Description
imagepolygon() creates a polygon in the given image.
Syntax
PHP imagepolygon() function has the following syntax.
bool imagepolygon ( resource $image , array $points , int $num_points , int $color )
Parameter
PHP imagepolygon() function has the following parameters.
- image - An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
- points - An array containing the polygon's vertices.
- num_points - Total number of points (vertices).
- color - A color identifier created with imagecolorallocate().
Point Format
Take a look at the following code:
$myPoints = array( 20, 20,
185, 55,
70, 80 );
imagepolygon( $myImage, $myPoints, 3, $myBlack );
This example creates an array of the polygon's points, called $myPoints. There are six elements in the array, or three x/y coordinate pairs.
This means that there are three corners to this polygon: at (20,20), (185,55), and (70,80).
Return
Returns TRUE on success or FALSE on failure.
Example
<?php/*from ja v a 2s .co m*/
// Create a blank image
$image = imagecreatetruecolor(400, 300);
// Allocate a color for the polygon
$col_poly = imagecolorallocate($image, 255, 255, 255);
// Draw the polygon
imagepolygon($image, array(
0, 0,
100, 200,
300, 200
),
3,
$col_poly);
// Output the picture to the browser
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
Next chapter...
What you will learn in the next chapter:
- What is PHP imagerectangle() function
- Syntax for PHP imagerectangle() function
- Parameter for PHP imagerectangle() function
- Return value for PHP imagerectangle() function
- Example - PHP imagerectangle() function
Home » PHP Tutorial » PHP Image Functions