From 4cfcc3b010cb854f22035a8f955bdbe5dd639746 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Tue, 13 Dec 2016 12:49:47 -0800 Subject: [PATCH 1/2] Tests for issue #1765 --- Tests/test_file_libtiff.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 77caa0b9d..7735b5bea 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -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") From 0a44d583149299a185754d0ac35e0eaaec60fc71 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 7 Sep 2018 20:35:55 +1000 Subject: [PATCH 2/2] Convert int values of RATIONAL TIFF tags to floats --- src/PIL/TiffImagePlugin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index 66b211cbf..c1a785ef3 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -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)