faressoft
faressoft

Reputation: 19651

How to draw a circle in img using php?

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

Upvotes: 5

Views: 15789

Answers (3)

CarlG
CarlG

Reputation: 610

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);

Upvotes: 23

Jamie Hurst
Jamie Hurst

Reputation: 331

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);

Upvotes: 5

Marc B
Marc B

Reputation: 360592

$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

Upvotes: 0

Related Questions