rkmax
rkmax

Reputation: 18135

Python3 PIL (Pillow) draw.pieslice bad arc

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?

Upvotes: 4

Views: 2374

Answers (2)

unutbu
unutbu

Reputation: 879351

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

Upvotes: 5

Ivan Borshchov
Ivan Borshchov

Reputation: 3549

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

Upvotes: 3

Related Questions