Merge pull request #2087 from cskau/patch-1

Fixes TIFFImagePlugin ICC color profile saving.
This commit is contained in:
wiredfool 2016-11-29 19:33:52 +00:00 committed by GitHub
commit e0b957240b
2 changed files with 20 additions and 4 deletions

View File

@ -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"),

View File

@ -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()