Skip to content

Commit

Permalink
Error handling for unsupported transparency
Browse files Browse the repository at this point in the history
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
  • Loading branch information
HTYISABUG committed Feb 18, 2024
1 parent 9d5becb commit 9d5dc58
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions modules/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,12 @@ def save_image_with_geninfo(image, geninfo, filename, extension=None, existing_p
else:
pnginfo_data = None

# Error handling for unsupported transparency in RGB mode
if (image.mode == "RGB" and
"transparency" in image.info and
isinstance(image.info["transparency"], bytes)):
del image.info["transparency"]

image.save(filename, format=image_format, quality=opts.jpeg_quality, pnginfo=pnginfo_data)

elif extension.lower() in (".jpg", ".jpeg", ".webp"):
Expand Down

0 comments on commit 9d5dc58

Please sign in to comment.