
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
How to draw an open polygon using the imageopenpolygon() function n PHP?
imageopenpolygon() is an inbuilt function in PHP that is used to draw an open polygon on a given image.
Syntax
bool imageopenpolygon(resource $image,array $points,int $num_points,int $color)
Parameters
imageopenpolygon() takes four different parameters: $image, $points, $num_points and$color.
$image − Specifies the image resource to work on.
$image − Specifies the image resource to work on.
$points − Specifies the points of the polygon.
$num_points − Specifies the number of points. The total number of (vertices) points must be at least three.
$color − This parameter specifies the color of the polygon.
Return Values
imageopenpolygon() returns True on success and False on failure.
Example 1
<?php // Create a blank image using imagecreatetruecolor() function. $img = imagecreatetruecolor(700, 300); // Allocate a color for the polygon $col_poly = imagecolorallocate($img, 0, 255, 0); // Draw the polygon imageopenpolygon($img, array( 0, 0, 100, 200, 400, 200 ), 3, $col_poly); // Output the picture to the browser header('Content-type: image/png'); imagepng($img); imagedestroy($img); ?>
Output
Example 2
<?php // Create a blank image using imagecreatetruecolor() function. $image = imagecreatetruecolor(700, 300); // allocate the colors $blue = imagecolorallocate($image, 0, 255, 255); // Six points of the array $points = array( 60, 130, 130, 230, 280, 230, 350, 130, 210, 30, 60, 130 ); // Create a polygon imageopenpolygon($image, $points, 6, $blue); // Output to the browser header('Content-type: image/png'); imagepng($image); imagedestroy($image); ?>
Output
- Related Articles
- How to draw a filled polygon using an imagefilledpolygon() function in PHP?
- How to draw an ellipse using imageellipse() function in PHP?
- Draw a filled polygon using the OpenCV function fillPoly()
- How to draw an octagon with Polygon object using FabricJS?
- How to draw a line using imageline() function in PHP?
- How to draw a string vertically using imagestringup() function in PHP?
- How to draw a polygon in OpenCV using Java?
- How to draw a hexagon with Polygon using FabricJS?
- How to draw a filled polygon in OpenCV using Java?
- How to draw a rectangle with Polygon object using FabricJS?
- How to crop an image to the given rectangle using imagecrop() function using PHP?
- How to draw a partial arc and fill it using imagefilledarc() function in PHP?
- How to draw a text string image horizontally by using imagestring() function in PHP?
- How to destroy an image in PHP using imagedestroy() function?
- How to crop an image automatically using imagecropauto() function in PHP?

Advertisements