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

Error handling for unsupported transparency #14958

Merged
merged 1 commit into from
Mar 4, 2024

Conversation

HTYISABUG
Copy link
Contributor

Description

When input images (palette mode) have transparency (bytes) in info, the output images (RGB mode) will inherit it, causing ValueError in Pillow:PIL/PngImagePlugin.py#1364 when trying to unpack this bytes.

This commit check the PNG mode and transparency info, removing transparency if it's RGB mode and transparency is bytes

Reproduce

Test file
634115967

  1. Goto Extras
  2. Goto Batch Process
  3. Run process on test file

Screenshots/videos:

Before
image

After
image

Checklist:

When input images (palette mode) have transparency (bytes) in info,
the output images (RGB mode) will inherit it,
causing ValueError in Pillow:PIL/PngImagePlugin.py#1364
when trying to unpack this bytes.

This commit check the PNG mode and transparency info,
removing transparency if it's RGB mode and transparency is bytes
@AUTOMATIC1111
Copy link
Owner

I get

A:\programs\Python310\lib\site-packages\PIL\Image.py:992: UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images

But no error. Using Pillow 9.5.0 as specified in the requirements file.

@HTYISABUG
Copy link
Contributor Author

I get

A:\programs\Python310\lib\site-packages\PIL\Image.py:992: UserWarning: Palette images with Transparency expressed in bytes should be converted to RGBA images

But no error. Using Pillow 9.5.0 as specified in the requirements file.

Strange.

I'm sure I am using Pillow 9.5.0,
and what Pillow do after the warning you get is similar to my patch.

I will check the reason, thanks for review.

@AUTOMATIC1111 AUTOMATIC1111 merged commit 5625ce1 into AUTOMATIC1111:dev Mar 4, 2024
3 checks passed
@AUTOMATIC1111
Copy link
Owner

Managed to reproduce it.

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 this pull request may close these issues.

None yet

2 participants