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

Misplaced polygon outline #8111

Closed
anloubie2 opened this issue Jun 7, 2024 · 1 comment · Fixed by #8112
Closed

Misplaced polygon outline #8111

anloubie2 opened this issue Jun 7, 2024 · 1 comment · Fixed by #8112

Comments

@anloubie2
Copy link

What did you do?

I drew a polygon on an image (16 bits grayscale)

What did you expect to happen?

The polygon should have been created at the specified coordinates

What actually happened?

The polygon was

What are your OS, Python and Pillow versions?

  • OS: MacOS Ventura 13.2.1
  • Python: 3.10
  • Pillow: 10.3.0
Please paste here the output of running:
python3 -m PIL --report

---------------------------------------------------------------------
Pillow 10.3.0
Python 3.10.11 (main, Apr  7 2023, 07:24:53) [Clang 14.0.0 (clang-1400.0.29.202)]
--------------------------------------------------------------------
Python executable is /Users/antoine/Envs/jupyter/bin/python3
Environment Python files loaded from /Users/antoine/Envs/jupyter
System Python files loaded from /opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10
--------------------------------------------------------------------
Python Pillow modules loaded from /Users/antoine/Envs/jupyter/lib/python3.10/site-packages/PIL
Binary Pillow modules loaded from /Users/antoine/Envs/jupyter/lib/python3.10/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.3.0
*** TKINTER support not installed
--- FREETYPE2 support ok, loaded 2.13.2
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.3.2
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 3.0.2
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.2
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1
--- LIBTIFF support ok, loaded 4.6.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.1, fribidi 1.0.13, harfbuzz 8.4.0
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------


When trying to draw a polygon on a 16 bits grayscale image, everything works fine with version 10.2.0 but the polygon is misplaced and its outline color is ignored with version 10.3.0.

Note that both these issues are fixed in 10.3.0 if a fill color is specified as well

10.2.0 with only outline 10.3.0 with only outline 10.3.0 with both outline and fill
10_2_0_outline 10_3_0_outline 10_3_0_fill_outline
from PIL import Image, ImageDraw

IMAGE_PATH = "./image.png"
WHITE = 65536
COORDINATES = [(1284.0, 1852.0), (1485.0, 1940.0), (1422.0, 2053.0), (1233.0, 1965.0)]


if __name__ == '__main__':
    image = Image.open(IMAGE_PATH)
    draw = ImageDraw.Draw(image)
    # This example works in 10.2.0 but not in 10.3.0
    draw.polygon(COORDINATES, outline=WHITE, width=15)
    # This example works in both 10.2.0 and 10.3.0
    # draw.polygon(COORDINATES, fill=WHITE, outline=WHITE, width=15)
    image.save('results.png')
    image.close()

Source image here:
image

@radarhere
Copy link
Member

The PNG you've attached is actually in L mode, not I;16*, so I can't replicate this exactly, but I expect #7849 is what triggered this change, by changing 16-bit grayscale PNGs to open in I;16 mode rather than I mode.

I've created #8112 to fix the polygon position.
Your value for WHITE is slightly too high for a 16-bit image at 65536 (0x10000), but if you change it to 65535 (0xFFFF), it should work.

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

Successfully merging a pull request may close this issue.

2 participants