Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Image Functions : imageellipse

imageellipse

Draw an ellipse (PHP 4 >= 4.0.6, PHP 5)
bool imageellipse ( resource image, int cx, int cy, int width, int height, int color )

Example 1006. imageellipse() example

<?php

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

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

// 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 picture
header("Content-type: image/png");
imagepng($image);

?>

The above example will output something similar to:


Related Examples ( Source code ) » imageellipse


Code Examples / Notes » imageellipse

agentyoungsoo

When you wana use "ImageEllipse" function
in under GD 2.0.2 version, you can use "ImageArc" like bellow
----------------------------------------------------
$file_name = "test.png";
$screen_x = 300;
$screen_y = 200;
$x1 = $screen_x / 2;
$y1 = $screen_y / 2;
$radius = 30;
$image = ImageCreate($screen_x, $screen_y);
$black = ImageColorAllocate($image, 0,0,0);
ImageArc($image, $x1, $y1, $radius , $radius , 0, 360, $black);
ImagePng($image, $file_name);
ImageDestroy($image);
----------------------------------------------------


simon_nuttall

This is an optimised and bug fixed version of nojer at yahoo dot com's rotatedellipse function. I've changed it so that the arguments are compatible with imageellipse. See notes on imagearc for original version.
<?php
function rotatedellipse($im, $cx, $cy, $width, $height, $rotateangle, $colour, $filled=false) {
 // modified here from nojer's version
 // Rotates from the three o-clock position clockwise with increasing angle.
 // Arguments are compatible with imageellipse.
 $width=$width/2;
 $height=$height/2;
 // This affects how coarse the ellipse is drawn.
 $step=3;
 $cosangle=cos(deg2rad($rotateangle));
 $sinangle=sin(deg2rad($rotateangle));
 // $px and $py are initialised to values corresponding to $angle=0.
 $px=$width * $cosangle;
 $py=$width * $sinangle;
 
 for ($angle=$step; $angle<=(180+$step); $angle+=$step) {
   
   $ox = $width * cos(deg2rad($angle));
   $oy = $height * sin(deg2rad($angle));
   
   $x = ($ox * $cosangle) - ($oy * $sinangle);
   $y = ($ox * $sinangle) + ($oy * $cosangle);

   if ($filled) {
     triangle($im, $cx, $cy, $cx+$px, $cy+$py, $cx+$x, $cy+$y, $colour);
     triangle($im, $cx, $cy, $cx-$px, $cy-$py, $cx-$x, $cy-$y, $colour);
   } else {
     imageline($im, $cx+$px, $cy+$py, $cx+$x, $cy+$y, $colour);
     imageline($im, $cx-$px, $cy-$py, $cx-$x, $cy-$y, $colour);
   }
   $px=$x;
   $py=$y;
 }
}
function triangle($im, $x1,$y1, $x2,$y2, $x3,$y3, $colour) {
  $coords = array($x1,$y1, $x2,$y2, $x3,$y3);
  imagefilledpolygon($im, $coords, 3, $colour);
}
?>


julian

if you want to display an ellipse in the upper left corner of an image, you can easily calculate the corresponding cx and cy values. this example will draw an ellipse having the same width and height as the image.
<?php
$ellipse_width = 100;
$ellipse_height = 200;
$ellipse_cx = ($ellipse_width / 2);
$ellipse_cy = ($ellipse_height / 2);
$img_x = $ellipse_width;
$img_y = $ellipse_height;
$img = imagecreate($img_x, $img_y);
$bg = imagecolorallocate($img, 255,255,255);
$ellipse_color = imagecolorallocate($img, 0, 0, 0);
imageellipse($img, $ellipse_cx, $ellipse_cy, $ellipse_width, $ellipse_height, $ellipse_color);
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);
?>


Change Language


Follow Navioo On Twitter
gd_info
getimagesize
image_type_to_extension
image_type_to_mime_type
image2wbmp
imagealphablending
imageantialias
imagearc
imagechar
imagecharup
imagecolorallocate
imagecolorallocatealpha
imagecolorat
imagecolorclosest
imagecolorclosestalpha
imagecolorclosesthwb
imagecolordeallocate
imagecolorexact
imagecolorexactalpha
imagecolormatch
imagecolorresolve
imagecolorresolvealpha
imagecolorset
imagecolorsforindex
imagecolorstotal
imagecolortransparent
imageconvolution
imagecopy
imagecopymerge
imagecopymergegray
imagecopyresampled
imagecopyresized
imagecreate
imagecreatefromgd2
imagecreatefromgd2part
imagecreatefromgd
imagecreatefromgif
imagecreatefromjpeg
imagecreatefrompng
imagecreatefromstring
imagecreatefromwbmp
imagecreatefromxbm
imagecreatefromxpm
imagecreatetruecolor
imagedashedline
imagedestroy
imageellipse
imagefill
imagefilledarc
imagefilledellipse
imagefilledpolygon
imagefilledrectangle
imagefilltoborder
imagefilter
imagefontheight
imagefontwidth
imageftbbox
imagefttext
imagegammacorrect
imagegd2
imagegd
imagegif
imagegrabscreen
imagegrabwindow
imageinterlace
imageistruecolor
imagejpeg
imagelayereffect
imageline
imageloadfont
imagepalettecopy
imagepng
imagepolygon
imagepsbbox
imagepsencodefont
imagepsextendfont
imagepsfreefont
imagepsloadfont
imagepsslantfont
imagepstext
imagerectangle
imagerotate
imagesavealpha
imagesetbrush
imagesetpixel
imagesetstyle
imagesetthickness
imagesettile
imagestring
imagestringup
imagesx
imagesy
imagetruecolortopalette
imagettfbbox
imagettftext
imagetypes
imagewbmp
imagexbm
iptcembed
iptcparse
jpeg2wbmp
png2wbmp
eXTReMe Tracker