Skip to content

Comments

Error handling for unsupported transparency#14958

Merged
AUTOMATIC1111 merged 1 commit intoAUTOMATIC1111:devfrom
HTYISABUG:dev
Mar 4, 2024
Merged

Error handling for unsupported transparency#14958
AUTOMATIC1111 merged 1 commit intoAUTOMATIC1111:devfrom
HTYISABUG:dev

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
@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.

2 participants