mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +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":
|
||||||
transparency = max(0, min(255, im.encoderinfo["transparency"]))
|
if isinstance(im.encoderinfo["transparency"], bytes):
|
||||||
alpha = b'\xFF' * transparency + b'\0'
|
chunk(fp, b"tRNS", b'\xFF' + im.encoderinfo["transparency"] + b'\0')
|
||||||
# limit to actual palette size
|
else:
|
||||||
alpha_bytes = 2**bits
|
transparency = max(0, min(255, im.encoderinfo["transparency"]))
|
||||||
chunk(fp, b"tRNS", alpha[:alpha_bytes])
|
chunk(fp, b"tRNS", b'\xFF' + transparency + b'\0')
|
||||||
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