Open In App

PHP | GmagickDraw ellipse() function

Last Updated : 23 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The GmagickDraw::ellipse() function is an inbuilt function in PHP which is used to draw an ellipse on the image.

Syntax:

GmagickDraw GmagickDraw::ellipse( float $ox, 
float $oy, float $rx, float $ry, 
float $start, float $end )

Parameters: This function accepts six parameters as mentioned above and described below:

  • $ox: It specifies the x-coordinate of the ellipse.
  • $oy: It specifies the y-coordinate of the ellipse.
  • $rx: It specifies the x-radius of the ellipse.
  • $ry: It specifies the y-radius of the ellipse.
  • $start: It specifies the start point of the ellipse.
  • $end: It specifies the end point of the ellipse.

Return Value: This function returns an GmagickDraw object on success.

Exceptions: This function throws GmagickDrawException on error.

Below given programs illustrate the GmagickDraw::ellipse() function in PHP:
Program 1 (Simple ellipse):




<?php
// Create a new Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
  
// Create a GmagickDraw object
$draw = new GmagickDraw();
  
// Set the color
$draw->setFillColor('#0E0E0E');
  
// Function to draw rectangle
$draw->rectangle(-10, -10, 800, 400);
  
// Set the fill color
$draw->setFillColor('#3D99D4');
  
// Set the stroke width
$draw->setStrokeWidth(5);
  
// Draw a ellipse 
$draw->ellipse(125, 70, 100, 50, 0, 360); 
  
// Use of drawimage function
$gmagick->drawImage($draw);
  
// Display the output image
header("Content-Type: image/png");
echo $gmagick->getImageBlob();
?>


Output:

Program 2 (Stroked ellipse):




<?php
// Create a new Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
  
// Create a GmagickDraw object
$draw = new GmagickDraw();
  
// Set the color
$draw->setFillColor('#0E0E0E');
  
// Function to draw rectangle
$draw->rectangle(-10, -10, 800, 400);
  
// Set the fill color
$draw->setFillColor('blue');
  
// Set the stroke color
$draw->setstrokecolor('green');
  
// Set the stroke width
$draw->setStrokeWidth(5);
  
// Draw a ellipse 
$draw->ellipse(225, 70, 150, 50, 0, 360); 
  
// Use of drawimage function
$gmagick->drawImage($draw);
  
// Display the output image
header("Content-Type: image/png");
echo $gmagick->getImageBlob();
?>


Output:

Reference: https://www.php.net/manual/en/gmagickdraw.ellipse.php



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads