Open In App

PHP | GmagickDraw rectangle() Function

Last Updated : 29 Jan, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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



Similar Reads

PHP | GmagickDraw setstrokewidth() Function
The GmagickDraw::setstrokewidth() function is an inbuilt function in PHP which is used to set the width of the stroke used to draw object outlines. Syntax: public GmagickDraw::setstrokewidth( $stroke_width ) : GmagickDraw Parameters: This function accepts single parameter $stroke_width which is used to hold the value of stroke width. It is a float
2 min read
PHP | GmagickDraw setfontstyle() Function
The GmagickDraw::setfontstyle() function is an inbuilt function in PHP that is used to set the font style to use when annotating with text. Style enumeration acts as a wild-card don't care option. Syntax: public GmagickDraw::setfontstyle( $style ) : GmagickDraw Parameters: This function accepts a single parameter $style which is used to hold the va
2 min read
PHP | GmagickDraw setfontweight() Function
The GmagickDraw::setfontweight() function is an inbuilt function in PHP that is used to set the font weight. Syntax: public GmagickDraw::setfontweight( $font_weight ) : GmagickDraw Parameters: This function accepts a single parameter $font_weight which is used to hold the value of font-weight as an integer type. Return Value: This function returns
2 min read
PHP | GmagickDraw settextdecoration() Function
The GmagickDraw ::settextdecoration() function is an inbuilt function in PHP that is used to specify the decoration to be applied when annotating with text. Syntax: public GmagickDraw::settextdecoration( $decoration ) : GmagickDraw Parameters: This function accepts a single parameter $decoration which is used to hold the value of DECORATION_ consta
2 min read
PHP | GmagickDraw setfillopacity() Function
The GmagickDraw ::setfillopacity() function is an inbuilt function in PHP which is used to set the opacity of a drawing image. It is used when drawing the image using the filled color or filled texture. Syntax: public GmagickDraw::setfillopacity( $fill_opacity ) : GmagickDraw Parameters: This function accepts single parameter $fill_opacity which is
2 min read
PHP | GmagickDraw setstrokecolor() Function
The GmagickDraw ::setstrokecolor() function is an inbuilt function in PHP which is used to set the color used for stroking object outlines. Syntax: public GmagickDraw::setstrokecolor( $color ) : GmagickDraw Parameters: This function accepts single parameter $color which is used to hold the color value. Return Value: This function returns the Gmagic
2 min read
PHP | GmagickDraw setstrokeopacity() Function
The GmagickDraw::setstrokeopacity() function is an inbuilt function in PHP that is used to specify the opacity of stroked object outlines. The value of opacity lies between 0 and 1. Syntax: public GmagickDraw::setstrokeopacity( $stroke_opacity ) : GmagickDraw Parameters: This function accepts a single parameter $stroke_opacity which is used to hold
2 min read
PHP | GmagickDraw scale() Function
The GmagickDraw::scale() function is an inbuilt function in PHP which is used to set the scaling factor and apply it to the horizontal and vertical directions to the current coordinate space.Syntax: public GmagickDraw::scale( $x, $y ) : GmagickDraw Parameters: This function accepts two parameter as mentioned above and described below: $x: This para
2 min read
PHP | GmagickDraw roundrectangle() Function
The GmagickDraw::roundrectangle() function is an inbuilt function in PHP which is used to draw a rounded rectangle. Syntax: public GmagickDraw::rectangle( $x1, $y1, $x2, $y2, $rx, $ry)   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
2 min read
PHP | GmagickDraw point() Function
The GmagickDraw::point() function is an inbuilt function in PHP which is used to draw a point. This function uses current stroke color and stroke thickness at the specified coordinates. Syntax: public GmagickDraw::point( $x, $y )   Parameters:This function accepts two parameters as mentioned above and described below: $x: This parameter takes the v
2 min read