3

I'm dawing a simple pieslice with PIL

image = Image.new("RGBA", (256, 128), "#DDD")
draw = ImageDraw.Draw(image, image.mode)
draw.pieslice((0, 0 , 64, 64), 180, 270, fill="white)

del draw

image.save("file.png", "PNG")

Image

As you can see the arc is not perfect. How I can make a perfect arc with PIL?

rkmax
  • 15,852
  • 22
  • 82
  • 170

2 Answers2

4

Draw on a larger image, then downscale:

N=4
image = Image.new("RGBA", (256*N, 128*N), "#DDD")
draw = ImageDraw.Draw(image, image.mode)
draw.pieslice((0, 0 , 64*N, 64*N), 180, 270, fill="white")
del draw
image = image.resize((256,128)) # using user3479125's correction
image.save("file2.png", "PNG")
unutbu
  • 711,858
  • 148
  • 1,594
  • 1,547
3

Note for unutbu's answer: Now the resize() returns a resized copy of an image. So it doesn't modify the original. So this should be:

N=4
image = Image.new("RGBA", (256*N, 128*N), "#DDD")
draw = ImageDraw.Draw(image, image.mode)
draw.pieslice((0, 0 , 64*N, 64*N), 180, 270, fill="white")
del draw
image = image.resize((256,128))
image.save("file2.png", "PNG")
Ivan Borshchov
  • 2,215
  • 3
  • 26
  • 56