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//from  w  w  w.  j a va  2  s. com

$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);

?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions