23

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)

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
ariel
  • 241
  • 1
  • 2
  • 6

4 Answers4

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

crifan
  • 12,947
  • 1
  • 71
  • 56
John La Rooy
  • 295,403
  • 53
  • 369
  • 502
  • 4
    `ellipse()` takes a bounding box (i.e. two sets of X/Y coordinates), not a set of X/Y coordinates and a pair of diameters. – kindall Sep 20 '11 at 16:22
10

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

Warm_Duscher
  • 686
  • 7
  • 14
YOU
  • 120,166
  • 34
  • 186
  • 219
9
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

reducing activity
  • 1,985
  • 2
  • 36
  • 64
user3086375
  • 99
  • 1
  • 2
4
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

evandrix
  • 6,041
  • 4
  • 27
  • 38
sid8491
  • 6,622
  • 6
  • 38
  • 64