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.
  • $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.
  • $ry: This parameter takes the value of radius of corner in vertical direction.
  • $rx: This parameter takes the value of radius of corner in horizontal direction.

Return Value: This function returns GmagickDraw object on success.

Errors/Exceptions: This function throws GmagickException on error.

Below programs illustrate the GmagickDraw::roundrectangle() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?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 roundrectangle  
$draw->roundrectangle(20, 20, 380, 465, 50, 50);
   
$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(); 
?> 

chevron_right


Output:

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php 
      
// Create a GmagickDraw object 
$draw = new ImagickDraw();  
     
// Set the color
$draw->setFillColor('Lightgreen'); 
   
// Set the width and height of image 
$draw->setStrokeWidth(7); 
$draw->setFontSize(72); 
      
// Function to draw roundrectangle  
$draw->roundrectangle(20, 20, 880, 465, 50, 50);
$draw->setFontSize(40); 
$draw->setFillColor('Green');  
$gmagick = new Imagick(); 
$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(); 
?> 

chevron_right


Output:

Reference: http://php.net/manual/en/gmagickdraw.roundrectangle.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.