Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a circle in img using php?

Tags:

php

gd

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

Image URL : image.jpg

I want to load the img then draw a circle on the orginal content of it

Before :

alt text

After :

alt text

like image 242
faressoft Avatar asked Dec 31 '10 21:12

faressoft


2 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);
like image 173
CarlG Avatar answered Sep 29 '22 10:09

CarlG


Start by loading the image, this function will be entirely dependant on what your source image is, but for now I'll guess it's a jpeg:

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

Then simply create the 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, simply use the following:

imagejpeg($img);
like image 30
Jamie Hurst Avatar answered Sep 29 '22 11:09

Jamie Hurst