diff --git a/PIL/PngImagePlugin.py b/PIL/PngImagePlugin.py index 7028083d7..f3738bd24 100644 --- a/PIL/PngImagePlugin.py +++ b/PIL/PngImagePlugin.py @@ -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)]) diff --git a/Tests/images/icc_profile_none.png b/Tests/images/icc_profile_none.png new file mode 100644 index 000000000..9ecff3a97 Binary files /dev/null and b/Tests/images/icc_profile_none.png differ diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py index 6a5954b79..99b00f718 100644 --- a/Tests/test_file_png.py +++ b/Tests/test_file_png.py @@ -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))