PHP | ImagickDraw polygon() Function
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 illsutrate the ImagickDraw::polygon() function in PHP:
Program:
<?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 gicen points $draw->polygon($points); // Create an Imagick object $image = new \Imagick(); // Ctrate 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
Recommended Posts:
- PHP | ImagickDraw arc() Function
- PHP | ImagickDraw scale() Function
- PHP | ImagickDraw bezier() Function
- PHP | ImagickDraw setStrokeLineJoin() Function
- PHP | ImagickDraw setFontFamily() Function
- PHP | ImagickDraw setFont() Function
- PHP | ImagickDraw setFontStyle() Function
- PHP | ImagickDraw setStrokeColor() Function
- PHP | ImagickDraw setTextAlignment() Function
- PHP | ImagickDraw circle() Function
- PHP | ImagickDraw setStrokeAlpha() Function
- PHP | ImagickDraw rotate() Function
- PHP | ImagickDraw roundRectangle() Function
- PHP | ImagickDraw setFillColor() Function
- PHP | ImagickDraw setGravity() 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.



