diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index 524d42a34..7e073b49d 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -1359,7 +1359,7 @@ def _save(im, fp, filename): IPTC_NAA_CHUNK, PHOTOSHOP_CHUNK, XMP): if key in im.tag_v2: ifd[key] = im.tag_v2[key] - ifd.tagtype[key] = im.tag_v2.tagtype.get(key, None) + 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 diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 9858ce5a0..9a2ce27d8 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -1,5 +1,6 @@ from __future__ import print_function import logging +from io import BytesIO import struct from helper import unittest, PillowTestCase, hopper, py3 @@ -103,6 +104,15 @@ class TestFileTiff(PillowTestCase): im._setup() self.assertEqual(im.info['dpi'], (71., 71.)) + def test_save_setting_missing_resolution(self): + from PIL.TiffImagePlugin import X_RESOLUTION, Y_RESOLUTION + b = BytesIO() + Image.open("Tests/images/10ct_32bit_128.tiff").save( + b, format="tiff", resolution=123.45) + im = Image.open(b) + self.assertEqual(float(im.tag_v2[X_RESOLUTION]), 123.45) + self.assertEqual(float(im.tag_v2[Y_RESOLUTION]), 123.45) + def test_invalid_file(self): invalid_file = "Tests/images/flower.jpg"