Merge pull request #2102 from radarhere/dpi

Convert DPI to ints when saving as JPEG
This commit is contained in:
wiredfool 2016-09-22 11:00:41 +01:00 committed by GitHub
commit 9415fb7e3c
2 changed files with 14 additions and 1 deletions

View File

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

View File

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