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
merged 1 commit into from Nov 21, 2021

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Aug 29, 2021

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
51 checks passed
@hugovk
Copy link
Member

@hugovk hugovk commented Nov 21, 2021

Thanks! Let's add release notes too.

@radarhere radarhere deleted the polygon_width branch Nov 21, 2021
@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 issue Nov 21, 2021
@radarhere
Copy link
Member Author

@radarhere radarhere commented Nov 22, 2021

Sure. See #5847

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

Successfully merging this pull request may close these issues.

2 participants