imagearc(): Circles and arcs

Circle using imagearac
<?Php
header ("Content-type: image/jpeg");
$width=300;$height=300;
$im = @ImageCreate ($width,$height) // added one pixel for border
or die ("Cannot Initialize new GD image stream");

$background_color = ImageColorAllocate ($im, 255, 255, 255);
$text_color = ImageColorAllocate ($im, 255, 0,0);
imagearc($im,150,150,290,290,0,360,$text_color); // outer face
imagearc($im,80,100,50,50,0,360,$text_color); // left eye 
imagearc($im,220,100,50,50,0,360,$text_color); // right eye
imagearc($im,150,150,150,150,45,135,$text_color); // mouth

Imagejpeg ($im);
imagedestroy($im); //memory is removed. 
?>
In above code we maintained $width and $height equal , $start_angle should be 0 (degree ) and $end_angle should be 360 ( degree ).

Syntax
imagearc($image,$center_x,$center_y,$width,$height,
	$start_angle,$end_angle,$color)
$imageImage created using ImageCreate() or imagecreatetruecolor()
$center_xx coordinate of center ( X : Horizontal )
$center_yy coordinate of center ( Y : Vertical )
$widthWidth of the arc
$heightHeight of the arc
$start_angle Angle of the start in degree. 3 Oclock position is 0 degree.
$end_angle Angle of the end of the arc in degree.
$colorColor of the borders by using imagecolorallocate().
imagearc with dimensions

Drawing arc, circles and patterns using different colours, width and height by imagearc() in PHP GD

Concentric circle using imagearc()

Common center for all the circles.
Circles using imagearac
<?Php
header ("Content-type: image/jpeg");
$width=601;$height=601;
$im = @ImageCreate ($width,$height) // added one pixel for border
or die ("Cannot Initialize new GD image stream");
$gap=20; // change this value to increase the lines 
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$text_color = ImageColorAllocate ($im, 0, 255,250);
imagesetthickness($im,1);
$text_color = ImageColorAllocate ($im, 255, 0,0);
for($i=0;$i<=$width;$i +=$gap){
imagearc($im,$width/2,$height/2,($width)-$i,($height)-$i,0,360,$text_color);
}
Imagejpeg ($im);
imagedestroy($im); //memory is removed. 
?>
Change the colours of the circle by using random numbers between 1 and 255 ( R G B )
Color Circles using imagearac
<?Php
header ("Content-type: image/jpeg");
$width=601;$height=601;
$im = @ImageCreate ($width,$height) // added one pixel for border
or die ("Cannot Initialize new GD image stream");
$gap=20; // change this value to increase the lines 
$background_color = ImageColorAllocate ($im, 255, 255, 255);
imagesetthickness($im,1);
$text_color = ImageColorAllocate ($im, 255, 0,0);
for($i=0;$i<=$width;$i +=$gap){
$r=rand(1,255);
$g=rand(1,255);
$b=rand(1,255);	
$text_color = ImageColorAllocate ($im, $r, $g,$b);		
imagearc($im,$width/2,$height/2,($width)-$i,($height)-$i,0,360,$text_color);
}

Imagejpeg ($im);
imagedestroy($im); //memory is removed. 
?>

Circle using imageellipse()

We can also use ellipse functions imageellipse() or imagefilledellipse() to draw circles by using equal width and height. Here there is no need to specify start angle and end angle.
GD functions imagefilledarc() imagerectangle() imageellipse() imagefilledellipse()
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here





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