Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, Draw a circle with PIL

Tags:

I am looking for a command that will draw a circle on an existing image with PIL.

im = Image.open(path)

I want a function that will draw a colored circle with radius r and center (x,y)

like image 763
ariel Avatar asked Jun 05 '10 12:06

ariel


People also ask

What does PIL do in Python?

Python Imaging Library is a free and open-source additional library for the Python programming language that adds support for opening, manipulating, and saving many different image file formats. It is available for Windows, Mac OS X and Linux. The latest version of PIL is 1.1.

How do I show a PIL image in Python?

Python – Display Image using PIL To show or display an image in Python Pillow, you can use show() method on an image object. The show() method writes the image to a temporary file and then triggers the default program to display that image. Once the program execution is completed, the temporary file will be deleted.


1 Answers

image = Image.open("x.png")
draw = ImageDraw.Draw(image)
leftUpPoint = (x-r, y-r)
rightDownPoint = (x+r, y+r)
twoPointList = [leftUpPoint, rightDownPoint]
draw.ellipse(twoPointList, fill=(255,0,0,255))

refer official doc: PIL.ImageDraw.ImageDraw.ellipse(xy, fill=None, outline=None, width=0)

like image 73
John La Rooy Avatar answered Oct 24 '22 14:10

John La Rooy