ariel
ariel

Reputation: 241

Python, Draw a circle with PIL

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)

Upvotes: 23

Views: 54299

Answers (4)

YOU
YOU

Reputation: 123791

Use ImageDraw.ellipse with square bbox like (0,0,10,10), which mean with diameter 10.

Upvotes: 10

John La Rooy
John La Rooy

Reputation: 304137

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)

Upvotes: 33

user3086375
user3086375

Reputation: 99

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

using this way i am unable to make it translucent, it is always opaque

This problem can be solved by the solution given here: How do you draw transparent polygons with Python?

Direct link: https://stackoverflow.com/a/21768191

Upvotes: 9

sid8491
sid8491

Reputation: 6800

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

using this way i am unable to make it translucent, it is always opaque

Upvotes: 5

Related Questions