How to Draw and Fill an Ellipse in PHP with imagefilledellipse

This guide explains the PHP GD function imagefilledellipse, detailing its parameters, return values, and a complete example that creates a blank image, fills the background, draws a white filled ellipse, and outputs the result as a PNG.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
How to Draw and Fill an Ellipse in PHP with imagefilledellipse

Function Overview

imagefilledellipse() draws a filled ellipse on a GD image resource. It returns the image resource on success or FALSE on failure.

Signature

bool imagefilledellipse ( resource $image , int $cx , int $cy , int $width , int $height , int $color )

Parameters

$image – Image resource created by functions such as imagecreatetruecolor().

$cx – X coordinate of the ellipse centre.

$cy – Y coordinate of the ellipse centre.

$width – Width of the ellipse.

$height – Height of the ellipse.

$color – Color identifier allocated with imagecolorallocate().

Example

<?php
// create a blank image
$image = imagecreatetruecolor(400, 300);

// fill the background with black
$bg = imagecolorallocate($image, 0, 0, 0);
imagefill($image, 0, 0, $bg);

// allocate white color for the ellipse
$col_ellipse = imagecolorallocate($image, 255, 255, 255);

// draw the filled ellipse
imagefilledellipse($image, 200, 150, 300, 200, $col_ellipse);

// output the image as PNG
header("Content-type: image/png");
imagepng($image);
?>

Result

The script produces a PNG image containing a white filled ellipse on a black background, similar to the illustration below.

Example output
Example output
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

GraphicsImage ProcessingPHPTutorialGDimagefilledellipse
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.