Backend Development 2 min read

PHP imageellipse Function: Drawing an Ellipse on an Image

The PHP imageellipse function draws an ellipse on a given image resource at specified coordinates, accepting parameters for the image, center coordinates, width, height, and color, and returns the image on success or FALSE on failure, as illustrated by a complete example script.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP imageellipse Function: Drawing an Ellipse on an Image

The imageellipse function in PHP draws an ellipse on a specified image resource at the given center coordinates ( cx , cy ) with defined width, height, and color.

Parameters

image : An image resource created by functions such as imagecreatetruecolor() .

cx : X coordinate of the ellipse center.

cy : Y coordinate of the ellipse center.

width : Width of the ellipse.

height : Height of the ellipse.

color : Color identifier allocated with imagecolorallocate() .

Return value

On success the function returns the image resource; on failure it returns FALSE .

Example usage

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

// Fill background color (black)
$bg = imagecolorallocate($image, 0, 0, 0);

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

// Draw an ellipse
imageellipse($image, 200, 150, 300, 200, $col_ellipse);

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

This script creates a 400×300 image, sets a black background, draws a white ellipse centered at (200,150) with a width of 300 and a height of 200, and outputs the result as a PNG image.

image processingBackend DevelopmentPHPGDellipseimageellipse
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

login 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.