Fix crash on save when icc_profile is None

This commit is contained in:
Bruno Renié 2014-01-19 16:40:39 +01:00
parent bb449f30ec
commit 0348fcac51
3 changed files with 8 additions and 1 deletions

View File

@ -618,7 +618,7 @@ def _save(im, fp, filename, chunk=putchunk, check=0):
name = p.tags.desc.get("ASCII", p.tags.desc.get("Unicode", p.tags.desc.get("Macintosh", p.tags.desc.get("en", {}).get("US", "ICC Profile")))).encode("latin1", "replace")[:79]
except ImportError:
name = b"ICC Profile"
data = name + b"\0\0" + zlib.compress(im.info["icc_profile"])
data = name or b'ICC Profile' + b"\0\0" + zlib.compress(im.info["icc_profile"])
chunk(fp, b"iCCP", data)
ImageFile._save(im, _idat(fp, chunk), [("zip", (0,0)+im.size, 0, rawmode)])

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -250,3 +250,10 @@ def test_trns_rgb():
im = roundtrip(im, transparency=(0, 1, 2))
assert_equal(im.info["transparency"], (0, 1, 2))
def test_save_icc_profile_none():
in_file = "Tests/images/icc_profile_none.png"
im = Image.open(in_file)
file = tempfile("temp.png")
assert_no_exception(lambda: im.save(file))