How to draw a circle in img using php?

How to draw a circle in (100px top and 100px on the left) img using php?

Image URL: image.jpg

I want to load img, then draw a circle on its original content

Before:

alt text

After:

alt text

+6
php gd
source share
3 answers

Take a look at imagefilledellipse

 // Create a image from file. $image = imagecreatefromjpeg('imgname.jpg'); // choose a color for the ellipse $ellipseColor = imagecolorallocate($image, 0, 0, 255); // draw the blue ellipse imagefilledellipse($image, 100, 100, 10, 10, $ellipseColor); // Output the image. header("Content-type: image/jpeg"); imagejpeg($image); 
+20
source share

Start by loading the image, this function will depend entirely on your original image, but for now I assume this is jpeg:

 $img = imagecreatefromjpeg('image.jpg'); 

Then just create a circle on the image:

 imagefilledellipse($img, 100, 100, 20, 20, 0x0000FF); 

I'm not sure how you want to return it, but to output it to the browser just use the following:

 imagejpeg($img); 
+5
source share
 $img = imagecreatetruecolor(300,300); // create a 300x300 image imagefilledellipse($img, 100, 100, 20, 20, 0x0000FF); /// draw a 20x20 circle at 100,100 using pure blue 
0
source share

All Articles