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: This parameter takes the value of y coordinate of the top left corner.
- $x2: This parameter takes the value of x coordinate of the bottom right.
- $y2: This parameter takes the value of y coordinate of the bottom right.
Return Value: This function returns TRUE on success.
Below program illustrate ImagickDraw rectangle() function in PHP:
Program:
<?php // require_once('vendor/autoload.php'); // Create ImagickDraw object $draw = new \ImagickDraw(); $draw->setStrokeColor('Green'); $draw->setFillColor('Red'); $draw->setStrokeWidth(7); $draw->rectangle(40, 30, 200, 260); // Create an image object which the draw // commands can be rendered into $image = new \Imagick(); $image->newImage(300, 300, 'White'); $image->setImageFormat("png"); // Render the draw commands in the ImagickDraw object // into the image. $image->drawImage($draw); // Send the image to the browser header("Content-Type: image/png"); echo $image->getImageBlob(); ?> |
Output:

Reference: http://php.net/manual/en/imagickdraw.rectangle.php
Recommended Posts:
- PHP | ImagickDraw arc() Function
- PHP | ImagickDraw setFont() Function
- PHP | ImagickDraw setFillColor() Function
- PHP | ImagickDraw setFontStyle() Function
- PHP | ImagickDraw setFontWeight() Function
- PHP | ImagickDraw setFontSize() Function
- PHP | ImagickDraw setFontFamily() Function
- PHP | ImagickDraw polygon() Function
- PHP | ImagickDraw roundRectangle() Function
- PHP | ImagickDraw setGravity() Function
- PHP | ImagickDraw skewX() Function
- PHP | ImagickDraw setStrokeOpacity() Function
- PHP | ImagickDraw translate() Function
- PHP | ImagickDraw setStrokeWidth() Function
- PHP | ImagickDraw setStrokeMiterLimit() 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.



