mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 10:26:19 +03:00
fixed bug with png-images with transparency palette
This commit is contained in:
parent
79ca29f2f5
commit
1ff2b6630a
|
@ -550,11 +550,11 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
|
||||||
|
|
||||||
if "transparency" in im.encoderinfo:
|
if "transparency" in im.encoderinfo:
|
||||||
if im.mode == "P":
|
if im.mode == "P":
|
||||||
|
if isinstance(im.encoderinfo["transparency"], bytes):
|
||||||
|
chunk(fp, b"tRNS", b'\xFF' + im.encoderinfo["transparency"] + b'\0')
|
||||||
|
else:
|
||||||
transparency = max(0, min(255, im.encoderinfo["transparency"]))
|
transparency = max(0, min(255, im.encoderinfo["transparency"]))
|
||||||
alpha = b'\xFF' * transparency + b'\0'
|
chunk(fp, b"tRNS", b'\xFF' + transparency + b'\0')
|
||||||
# limit to actual palette size
|
|
||||||
alpha_bytes = 2**bits
|
|
||||||
chunk(fp, b"tRNS", alpha[:alpha_bytes])
|
|
||||||
elif im.mode == "L":
|
elif im.mode == "L":
|
||||||
transparency = max(0, min(65535, im.encoderinfo["transparency"]))
|
transparency = max(0, min(65535, im.encoderinfo["transparency"]))
|
||||||
chunk(fp, b"tRNS", o16(transparency))
|
chunk(fp, b"tRNS", o16(transparency))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user