mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-23 19:44:13 +03:00
Merge pull request #150 from d-schmidt/master
fixing save of transparency palette png-images
This commit is contained in:
commit
2e888483a6
|
@ -70,7 +70,7 @@ _MODES = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
_simple_palette = re.compile(b'^\xff+\x00+$')
|
_simple_palette = re.compile(b'^\xff+\x00\xff*$')
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# Support classes. Suitable for PNG and related formats like MNG etc.
|
# Support classes. Suitable for PNG and related formats like MNG etc.
|
||||||
|
@ -550,11 +550,14 @@ 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"]))
|
|
||||||
alpha = b'\xFF' * transparency + b'\0'
|
|
||||||
# limit to actual palette size
|
# limit to actual palette size
|
||||||
alpha_bytes = 2**bits
|
alpha_bytes = 2**bits
|
||||||
chunk(fp, b"tRNS", alpha[:alpha_bytes])
|
if isinstance(im.encoderinfo["transparency"], bytes):
|
||||||
|
chunk(fp, b"tRNS", im.encoderinfo["transparency"][:alpha_bytes])
|
||||||
|
else:
|
||||||
|
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":
|
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