Merge pull request #3338 from radarhere/int_dpi

Convert int values of RATIONAL TIFF tags to floats
This commit is contained in:
Hugo 2018-09-08 10:55:16 +03:00 committed by GitHub
commit 1defb1aceb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -231,6 +231,16 @@ class TestFileLibTiff(LibTiffTestCase):
TiffImagePlugin.WRITE_LIBTIFF = False
def test_int_dpi(self):
# issue #1765
im = hopper('RGB')
out = self.tempfile('temp.tif')
TiffImagePlugin.WRITE_LIBTIFF = True
im.save(out, dpi=(72, 72))
TiffImagePlugin.WRITE_LIBTIFF = False
reloaded = Image.open(out)
self.assertEqual(reloaded.info['dpi'], (72.0, 72.0))
def test_g3_compression(self):
i = Image.open('Tests/images/hopper_g4_500.tif')
out = self.tempfile("temp.tif")

View File

@ -567,6 +567,9 @@ class ImageFileDirectory_v2(MutableMapping):
if self.tagtype[tag] == 7 and py3:
values = [value.encode("ascii", 'replace') if isinstance(
value, str) else value]
elif self.tagtype[tag] == 5:
values = [float(v) if isinstance(v, int) else v
for v in values]
values = tuple(info.cvt_enum(value) for value in values)