fixing save of transparency palette png-images

This commit is contained in:
David Schmidt 2013-03-21 18:16:00 +01:00
parent 1ff2b6630a
commit 09315f263b

View File

@ -550,11 +550,14 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
if "transparency" in im.encoderinfo:
if im.mode == "P":
# limit to actual palette size
alpha_bytes = 2**bits
if isinstance(im.encoderinfo["transparency"], bytes):
chunk(fp, b"tRNS", b'\xFF' + im.encoderinfo["transparency"] + b'\0')
chunk(fp, b"tRNS", im.encoderinfo["transparency"][:alpha_bytes])
else:
transparency = max(0, min(255, im.encoderinfo["transparency"]))
chunk(fp, b"tRNS", b'\xFF' + transparency + b'\0')
transparency = max(0, min(255, im.encoderinfo["transparency"]))
alpha = b'\xFF' * transparency + b'\0'
chunk(fp, b"tRNS", alpha[:alpha_bytes])
elif im.mode == "L":
transparency = max(0, min(65535, im.encoderinfo["transparency"]))
chunk(fp, b"tRNS", o16(transparency))