Skip to content

Conversation

@radarhere
Copy link
Member

Helps #4277

When Pillow draws an ellipse, it considers it to be a 360-sided shape. Expressing that within an ordinary width and height means that those edges overlap.

In such a situation, the polygon_generic function will draw pixels more than once. This is usually unnoticed, since a solid pixel on top of another solid pixel is still just a solid pixel. However, if the pixels drawn have a partial opacity, then repeated drawing of a pixel changes the final opacity.

from PIL import Image, ImageDraw im = Image.new('RGB', (45, 45), (255, 255, 255)) d = ImageDraw.Draw(im, 'RGBA') d.ellipse([(0, 0), (45, 45)], (0, 0, 255, 100)) im.save('out.png')

out

As background, the polygon_generic function uses a scanline algorithm, drawing each row in turn,. Within each row, it starts drawing a line at the edge of a polygon, stops at the next edge, starts at the following edge, and so on.

This PR updates the function to only draw each pixel once.

out

@hugovk
Copy link
Member

hugovk commented Feb 15, 2020

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants