diff --git a/PIL/JpegImagePlugin.py b/PIL/JpegImagePlugin.py index a0d066724..815ee02b6 100644 --- a/PIL/JpegImagePlugin.py +++ b/PIL/JpegImagePlugin.py @@ -593,7 +593,7 @@ def _save(im, fp, filename): info = im.encoderinfo - dpi = info.get("dpi", (0, 0)) + dpi = [int(round(x)) for x in info.get("dpi", (0, 0))] quality = info.get("quality", 0) subsampling = info.get("subsampling", -1) diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index d04218b1a..5e66cc765 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -469,6 +469,19 @@ class TestFileJpeg(PillowTestCase): img = Image.new(mode, (20, 20)) self.assert_warning(DeprecationWarning, img.save, out, "JPEG") + def test_save_tiff_with_dpi(self): + # Arrange + outfile = self.tempfile("temp.tif") + im = Image.open("Tests/images/hopper.tif") + + # Act + im.save(outfile, 'JPEG', dpi=im.info['dpi']) + + # Assert + reloaded = Image.open(outfile) + reloaded.load() + self.assertEqual(im.info['dpi'], reloaded.info['dpi']) + if __name__ == '__main__': unittest.main()