imagefilledellipse(): Filled ellipse using PHP GD

<?Php
header ("Content-type: image/jpeg");
$width=301;$height=250;
$im = @ImageCreate ($width, $height) 
 or die ("Cannot Initialize new GD image stream");
ImageColorAllocate($im,255,255,255);

$text_color=ImageColorAllocate($im,255,0,0);  // border colour  
$fill_color=ImageColorAllocate($im,0,128,255); // fill colour 
imagefilledellipse($im,150,125,250,140,$fill_color); // draw ellipse and fill colour

Imagejpeg ($im); // show the filled ellipse 
imagedestroy($im); //memory is cleared.
?>
filled ellipse using imagefilledellipse()
Syntax
imagefilledellipse($image,$center_x,$center_y,$width,$height,$color)
Returns true or false based on success of failure.
$imageImage created using ImageCreate() or imagecreatetruecolor()
$center_xx coordinate of center ( X : Horizontal )
$center_yy coordinate of center ( Y : Vertical )
$widthWidth of the ellipse
$heightHeight of the ellipse
$colorColor to fill the ellipse by using imagecolorallocate().

Creating full circle using imagefilledellipse()

We need to maintain $width and $height equal .
By using imageellipse() we created one face, to this image now we will be adding eye balls by using imagefilledellipse().

Example

Face with eye balls using imagefilledellipse
<?Php
header ("Content-type: image/jpeg");
$width=301;$height=301;
$im = @ImageCreate ($width, $height) 
 or die ("Cannot Initialize new GD image stream");
ImageColorAllocate($im,255,255,255);
$text_color=ImageColorAllocate($im,255,0,0);   
imageellipse($im,150,150,290,290,$text_color); // outer face
imageellipse($im,80,100,50,50,$text_color); // left eye 
imageellipse($im,220,100,50,50,$text_color); // right eye
imageellipse($im,150,200,70,10,$text_color); // mouth

$fill_color=ImageColorAllocate($im,0,128,255); // eye ball colour
imagefilledellipse($im,80,100,20,20,$fill_color); // left eye ball
imagefilledellipse($im,220,100,20,20,$fill_color); // right eye ball
 Imagejpeg ($im);
 imagedestroy($im); //memory is cleared.
?>
By changing the position of eye ball we can create different type of face ( emoji )
Face with eye balls in down direction
$move_left=0;
$move_top=-15;
Face with eye balls in right direction
$move_left=-15;
$move_top=0;
$move_left=-15; // x position is moved right 
$move_top=0; // Y position not changed  
$fill_color=ImageColorAllocate($im,0,245,255);
imagefilledellipse($im,80-$move_left,100-$move_top,20,20,$fill_color); 
imagefilledellipse($im,220-$move_left,100-$move_top,20,20,$fill_color);
Try to create different movement of eye balls and mouth ellipse representing different face expressions ( emoji )

Concentric circle using imagefilledellipse()

Random numbers are gnerated between 1 and 255 for adding differnt colors. Common center for all the circles.
Filled concentric Circles using imagefilledellipse
<?Php
header ("Content-type: image/jpeg");
$width=601;$height=601;$gap=30;
$im = @ImageCreate ($width, $height) 
 or die ("Cannot Initialize new GD image stream");
ImageColorAllocate($im,255,255,255);
for($i=0;$i<=$width;$i +=$gap){
    $r=rand(1,255);
    $g=rand(1,255);
    $b=rand(1,255);	
    $fill_color = ImageColorAllocate ($im, $r, $g,$b);    
imagefilledellipse($im,$width/2,$height/2,$width-$i,$height-$i,$fill_color);
}
Imagejpeg ($im);
imagedestroy($im); //memory is cleared.
?>
GD functions GD imagearc() GD imagerectangle()
GD imagefilledarc() : Draw filled arcs to create PIE chat
GD imagefilledrectangle() to create Bar Chat

Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer