Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added line width argument to ImageDraw polygon #5694

merged 1 commit into from Nov 21, 2021


Copy link

Resolves #5689

If we just drew thicker lines when creating a polygon, then since the centre of the line is the edge, half of each line would be drawn outside the filled polygon.

This PR uses masking to trim the outer half.

Because the image might have any mode, and there are limited modes that can be used as a mask,

  • I draw the filled polygon on a 1-bit image, fill_im
  • I draw the outline of the polygon on a 1-bit image, ink_im, which extends outside the filled polygon
  • I use fill_im as a mask to trim the polygon outline to just the inner part, giving a 1-bit mask.
  • Then I create an image with the destination mode, draw the outline, and use mask to paste only the inner part on the original image.

@hugovk hugovk merged commit c857366 into python-pillow:main Nov 21, 2021
Copy link

hugovk commented Nov 21, 2021

Thanks! Let's add release notes too.

@radarhere radarhere deleted the polygon_width branch November 21, 2021 21:27
@radarhere radarhere changed the title Added width argument to ImageDraw polygon Added line width argument to ImageDraw polygon Nov 21, 2021
radarhere added a commit to radarhere/Pillow that referenced this pull request Nov 21, 2021
Copy link
Member Author

Sure. See #5847

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

Successfully merging this pull request may close these issues.

Add width to polygon
2 participants