Friday, November 21, 2025
HomeLanguagesPHP | imageellipse() Function

PHP | imageellipse() Function

The imageellipse() function is an inbuilt function in PHP which is used to draw an ellipse. This function returns TRUE on success or FALSE on failure.

Syntax:

bool imageellipse( $image, $cx, $cy, $width, $height, $color )

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

  • $image: It is returned by one of the image creation functions, such as imagecreatetruecolor(). It is used to create size of image.
  • $cx: x-coordinate of the center.
  • $cy: y-coordinate of the center.
  • $width: The ellipse width.
  • $height: The ellipse height.
  • $color: It sets the color of ellipse. A color identifier created by imagecolorallocate() function.

Return Value: It returns TRUE on success or FALSE on failure.

Below programs illustrate the imageellipse() function in PHP:

Program 1:




<?php
   
// It create the size of image or blank image.
$image_size = imagecreatetruecolor(500, 300);
   
// Set the background color of image.
$background_color = imagecolorallocate($image_size, 255, 255, 255);
   
// Fill background with above selected color.
imagefill($image_size, 0, 0, $background_color);
   
// set color of ellipse.
$ellipse_color = imagecolorallocate($image_size, 0, 0, 0);
   
// Function to draw the ellipse.
imageellipse($image_size, 250, 150, 400, 250, $ellipse_color);
   
// Output the image.
header("Content-type: image/png");
imagepng($image_size);
   
?>


Output:

ellipse

Program 2:




<?php
   
// It create the size of image or blank image.
$image = imagecreatetruecolor(300, 500);
   
// Set the background color of image.
$bg = imagecolorallocate($image, 0, 102, 0);
   
// Fill background with above selected color.
imagefill($image, 0, 0, $bg);
   
// set color of ellipse.
$col_ellipse = imagecolorallocate($image, 255, 255, 255);
   
// Function to draw the ellipse.
imageellipse($image, 150, 250, 250, 400, $col_ellipse);
   
// Output the image.
header("Content-type: image/png");
imagepng($image);
   
?>


Output:

ellipse

Reference: http://php.net/manual/en/function.imageellipse.php

RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6783 POSTS0 COMMENTS
Nicole Veronica
11929 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS