Open In App

PHP | ImagickDraw polygon() Function

Last Updated : 10 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The ImagickDraw::polygon() function is an inbuilt function in Imagick library in PHP which is used to draw a polygon using the specified array of coordinates.

Syntax: 

bool ImagickDraw::polygon( $coordinates )

Parameters: This function accepts single parameter $coordinates of array type. It is used to hold the set of points.
Return Value: This function returns TRUE on success.

Below program illustrate the ImagickDraw::polygon() function in PHP: 

Program:  

PHP




<?php
     
// require_once('vendor/autoload.php');
 
// Create an ImagickDraw object
$draw = new \ImagickDraw();
 
// Set the opacity of image
$draw->setStrokeOpacity(1);
 
// Set the color of image
$draw->setStrokeColor('Green');
 
// Set the stroke width
$draw->setStrokeWidth(4);
 
// Set the fill color
$draw->setFillColor('Red');
 
// Array contains points
$points = [
    ['x' => 50 * 6, 'y' => 10 * 5],
    ['x' => 20 * 7, 'y' => 30 * 5],
    ['x' => 60 * 8, 'y' => 50 * 5],
    ['x' => 70 * 3, 'y' => 15 * 5],
];
 
// Draw the polygon with given points
$draw->polygon($points);
 
// Create an Imagick object
$image = new \Imagick();
 
// Create an image of given size
$image->newImage(500, 300, 'white');
 
// Set the image format
$image->setImageFormat("png");
 
// Draw the image
$image->drawImage($draw);
 
header("Content-Type: image/png");
 
// Display the output image
echo $image->getImageBlob();
?>


Output: 
 

Reference: http://php.net/manual/en/imagickdraw.polygon.php
 


Similar Reads

PHP | ImagickDraw getTextAlignment() Function
The ImagickDraw::getTextAlignment() function is an inbuilt function in PHP which is used to get the alignment applied when annotating with text. It helps to format the text by making it stick to left, right or middle. Syntax: int ImagickDraw::getTextAlignment( void ) Parameters: This function doesn’t accept any parameter. Return Value: This functio
2 min read
PHP | ImagickDraw scale() Function
The ImagickDraw::scale() function is an inbuilt function in PHP which is used to adjust the scaling factor to apply in the horizontal and vertical directions to the current coordinate space. Syntax: bool ImagickDraw::scale( $x, $y ) Parameters: This function accepts two parameter as mentioned above and described below: $x: This parameter is used to
2 min read
PHP | ImagickDraw roundRectangle() Function
The ImagickDraw::roundRectangle() function is an inbuilt function in Imagick library of PHP which is used to draw a rounded rectangle. Syntax: bool ImagickDraw::roundRectangle( $x1, $y1, $x2, $y2, $rx, $ry ) Parameters: This function accept six parameters as mentioned above and described below: $x1: This parameter takes the value of x coordinate of
2 min read
PHP | ImagickDraw arc() Function
The ImagickDraw::arc() function is an inbuilt function in Imagick library of PHP which is used to draw an arc. Syntax: bool ImagickDraw::arc( $sx, $sy, $ex, $ey, $sd, $ed ) Parameters: This function accepts six parameters as mentioned above and described below: $sx: This parameter takes the value of starting x-ordinate. $sy: This parameter takes th
1 min read
PHP | ImagickDraw circle() Function
The ImagickDraw::circle() function is an inbuilt function in Imagick library of PHP which is used to draw a circle. Syntax: bool ImagickDraw::circle( $ox, $oy, $px, $py ) Parameters: This function accepts four parameters as mentioned above and described below: $ox: This parameter takes the value of origin x-coordinate. $oy: This parameter takes the
1 min read
PHP | ImagickDraw bezier() Function
The ImagickDraw::bezier() function is an inbuilt function in Imagick library of PHP which is used to draw bezier curve. Syntax: bool ImagickDraw::bezier( $coordinates ) Parameters: This function accepts a single parameter as the multidimensional array which takes the points through which curve is to be made. Return Value: This function does not ret
1 min read
PHP | ImagickDraw rectangle() Function
The ImagickDraw::rectangle() function is an inbuilt function in Imagick library of PHP which is used to draw a rectangle. Syntax: bool ImagickDraw::rectangle( $x1, $y1, $x2, $y2 ) Parameters: This function accepts four parameters as mentioned above and described below: $x1: This parameter takes the value of x coordinate of the top left corner. $y1:
1 min read
PHP | ImagickDraw line() Function
The ImagickDraw::line() function is an inbuilt function in Imagick library of PHP which is used to draw a line. This function draw the line using the current stroke color, stroke opacity, and stroke width. Syntax: bool ImagickDraw::line( $sx, $sy, $ex, $ey ) Parameters: This function accepts four parameters as mentioned above and described below: $
1 min read
PHP | ImagickDraw point() Function
The ImagickDraw::point() function is an inbuilt function in Imagick library of PHP which is used to draw a point. This function uses current stroke color and stroke thickness at the specified coordinates. Syntax: bool ImagickDraw::point( $x, $y ) Parameters: This function accepts two parameters as mentioned above and described below: $x: This param
1 min read
PHP | ImagickDraw skewX() Function
The ImagickDraw::skewX() function is an inbuilt function in PHP which is used to skews the current coordinate system in the horizontal direction. Syntax: bool ImagickDraw::skewX( $degrees ) Parameters: This function accepts a single parameter $degrees which is used to hold the degrees to skew. Return Value: This function does not return any value.
2 min read