Tuesday, September 16, 2025
HomeLanguagesPHP | GmagickDraw ellipse() function

PHP | GmagickDraw ellipse() function

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('neveropen.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('neveropen.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

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32293 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6656 POSTS0 COMMENTS
Nicole Veronica
11826 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11892 POSTS0 COMMENTS
Shaida Kate Naidoo
6773 POSTS0 COMMENTS
Ted Musemwa
7044 POSTS0 COMMENTS
Thapelo Manthata
6729 POSTS0 COMMENTS
Umr Jansen
6739 POSTS0 COMMENTS