PHP | GmagickDraw rectangle() Function
The GmagickDraw::rectangle() function is an inbuilt function in PHP which is used to draw the rectangle.
Syntax:
public GmagickDraw::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 GmagickDraw object on success.
Errors/Exceptions: This function throws GmagickException on error.
Below programs illustrate the GmagickDraw::rectangle() function in PHP:
Program 1:
<?php // Create a GmagickDraw object $draw = new GmagickDraw(); // Set the color $draw->setFillColor('Green'); // Set the width and height of image $draw->setStrokeWidth(7); $draw->setFontSize(72); // Function to draw rectangle $draw->rectangle(20, 20, 380, 465); $gmagick = new Gmagick(); $gmagick->newImage(500, 500, 'White'); $gmagick->setImageFormat("png"); // Use of drawimage function $gmagick->drawImage($draw); // Display the output image header("Content-Type: image/png"); echo $gmagick->getImageBlob(); ?> |
Output:

Program 2:
<?php // Create a GmagickDraw object $draw = new GmagickDraw(); // Set the color $draw->setFillColor('Lightgreen'); // Set the width and height of image $draw->setStrokeWidth(7); $draw->setFontSize(72); // Function to draw rectangle $draw->rectangle(20, 20, 880, 465); $draw->setFontSize(40); $draw->setFillColor('Green'); $gmagick = new Gmagick(); $gmagick->newImage(900, 500, 'White'); $gmagick->setImageFormat("png"); // Use of drawimage function $gmagick->drawImage($draw); // Annotate Image $gmagick->annotateImage($draw, 5, 120, 0, ' GeeksforGeeks: A computer science portal'); $gmagick->annotateImage($draw, 5, 220, 0, ' sarthak_ishu11'); // Display the output image header("Content-Type: image/png"); echo $gmagick->getImageBlob(); ?> |
Output:

Reference: http://php.net/manual/en/gmagickdraw.rectangle.php
Recommended Posts:
- PHP | GmagickDraw getstrokeopacity() Function
- PHP | GmagickDraw getfontsize() Function
- PHP | GmagickDraw scale() Function
- PHP | GmagickDraw setfontsize() Function
- PHP | GmagickDraw setstrokecolor() Function
- PHP | GmagickDraw setstrokeopacity() Function
- PHP | GmagickDraw getstrokewidth() Function
- PHP | GmagickDraw line() Function
- PHP | GmagickDraw setfontstyle() Function
- PHP | GmagickDraw setstrokewidth() Function
- PHP | GmagickDraw settextdecoration() Function
- PHP | GmagickDraw setfontweight() Function
- PHP | GmagickDraw setfillopacity() Function
- PHP | GmagickDraw point() Function
- PHP | GmagickDraw roundrectangle() 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.



