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.
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.
Laravel Tech Community
Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.