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, ' w3wiki: 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