PHP imageellipse() function

In this chapter you will learn:

  1. What is PHP imageellipse() function
  2. Syntax for PHP imageellipse() function
  3. Parameter for PHP imageellipse() function
  4. Return value for PHP imageellipse() function
  5. Drawing Circles and Ellipses
  6. Example - PHP imageellipse() function

Description

Draws an ellipse centered at the specified coordinates.

Syntax

PHP imageellipse() function has the following syntax.

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

Parameter

PHP imageellipse() function has the following parameters.

  • image - An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().
  • cx - x-coordinate of the center.
  • cy - y-coordinate of the center.
  • width - The ellipse width.
  • height - The ellipse height.
  • color - The color of the ellipse. A color identifier created with imagecolorallocate().

Return

Returns TRUE on success or FALSE on failure.

Drawing Circles and Ellipses

To draw circles and ellipses in PHP, use the imageellipse() function.

We provide the center point, and then specifying how high and how wide the ellipse should be.

imageellipse( $myImage, 90, 60, 160, 50, $myBlack );

This ellipse has its center on the pixel at (90,60). The width of the ellipse is 160 pixels and the height is 50 pixels.

To draw a circle, simply describe an ellipse that has the same width and height:

imageellipse( $myImage, 90, 60, 70, 70, $myBlack );

Example


<?php/*  j a  va 2s. c o  m*/

$image = imagecreatetruecolor(400, 300);

// Select the background color.
$bg = imagecolorallocate($image, 0, 0, 0);

// Fill the background with the color selected above.
imagefill($image, 0, 0, $bg);

// Choose a color for the ellipse.
$col_ellipse = imagecolorallocate($image, 255, 255, 255);

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

// Output the image.
header("Content-type: image/png");
imagepng($image);

?>

Next chapter...

What you will learn in the next chapter:

  1. What is PHP imagefilledarc() function
  2. Syntax for PHP imagefilledarc() function
  3. Parameter for PHP imagefilledarc() function
  4. Return value for PHP imagefilledarc() function
  5. Example - Draw a pie
  6. Example - PHP imagefilledarc() function
Home » PHP Tutorial » PHP Image Functions
PHP imagearc() function
PHP imagecreate() function
PHP imagecreatetruecolor () function
PHP imageellipse() function
PHP imagefilledarc() function
PHP imageline() function
PHP imagepolygon() function
PHP imagerectangle() function
PHP imagesetpixel() function
PHP imagettftext() function