fixed bug with png-images with transparency palette

This commit is contained in:
David Schmidt 2013-03-21 16:54:04 +01:00
parent 79ca29f2f5
commit 1ff2b6630a

View File

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