Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 712
rkmax Avatar asked Feb 16 '23 12:02

rkmax


2 Answers

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")
like image 154
unutbu Avatar answered Feb 19 '23 02:02

unutbu


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")
like image 32
Ivan Borshchov Avatar answered Feb 19 '23 02:02

Ivan Borshchov