diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index f1860e4aa..810f99e75 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -1362,10 +1362,10 @@ def _save(im, fp, filename): ifd[key] = im.tag_v2[key] ifd.tagtype[key] = im.tag_v2.tagtype[key] - # preserve ICC profile (should also work when saving other formats - # which support profiles as TIFF) -- 2008-06-06 Florian Hoech - if "icc_profile" in im.info: - ifd[ICCPROFILE] = im.info["icc_profile"] + # preserve ICC profile (should also work when saving other formats + # which support profiles as TIFF) -- 2008-06-06 Florian Hoech + if "icc_profile" in im.info: + ifd[ICCPROFILE] = im.info["icc_profile"] for key, name in [(IMAGEDESCRIPTION, "description"), (X_RESOLUTION, "resolution"), diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 9913860ad..76fe8f930 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -499,5 +499,21 @@ class TestFileTiff(PillowTestCase): with Image.open(mp) as im: self.assertEqual(im.n_frames, 3) + def test_saving_icc_profile(self): + # Tests saving TIFF with icc_profile set. + # At the time of writing this will only work for non-compressed tiffs + # as libtiff does not support embedded ICC profiles, ImageFile._save(..) + # however does. + im = Image.new('RGB', (1, 1)) + im.info['icc_profile'] = 'Dummy value' + + # Try save-load round trip to make sure both handle icc_profile. + tmpfile = self.tempfile('temp.tif') + im.save(tmpfile, 'TIFF', compression='raw') + reloaded = Image.open(tmpfile) + + self.assertEqual(b'Dummy value', reloaded.info['icc_profile']) + + if __name__ == '__main__': unittest.main()