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

Polygons aren't drawn the same #6908

Closed
vinh-00 opened this issue Jan 24, 2023 · 3 comments
Closed

Polygons aren't drawn the same #6908

vinh-00 opened this issue Jan 24, 2023 · 3 comments

Comments

@vinh-00
Copy link

vinh-00 commented Jan 24, 2023

Hi,
I'm currently trying to migrate py2 to py3, from Pillow 6.2.1 to 9.3.0
I'm noticing some strange behaviors in the draw polygon functions, where my inputs are the same, but the outputs are slightly different.
Heres a test case below, to run on py2.7 remove the width arg.

from PIL import Image, ImageDraw
import numpy as np

def pil_test():

  poly = [(402,  52),(402,  52),(406,  54),(405,  55)]

  img = Image.new('I', (500, 500))
  draw = ImageDraw.Draw(img, mode='I')
  draw.polygon(poly, fill=100, width=0) 
  ## py2 - draw.polygon(poly, fill=100)
  
  iarr = np.array(img)
  print(iarr[52,403])

Pillow 6.2.1 output >> 0
Pillow 9.3.0 output >> 100

I would like to know if theres a workaround for this? or why is this happening?

@Yay295
Copy link
Contributor

Yay295 commented Jan 24, 2023

The default width for polygon() is 1. Have you tried using the default?

@radarhere
Copy link
Member

Testing, I find that the difference is because of #5980. This resolved #4347, where there was a request that the following polygon not be discontiguous.

Screen Shot 2020-01-08 at 4 58 26 PM

So, if your question is just a general one about why the latest version of Pillow might draw a polygon differently to an earlier version of Pillow, that is why. The change was introduced in Pillow 9.1.0, so if you would like to upgrade to Python 3 without including this change in Pillow, you can use Pillow 9.0.0 instead.

@vinh-00
Copy link
Author

vinh-00 commented Jan 24, 2023

Thank you for the explanation and workaround.

@vinh-00 vinh-00 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants