Skip to content

Commit

Permalink
Convert DPI to ints when saving as JPEG
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Sep 22, 2016
1 parent 50ab008 commit 051a410
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion PIL/JpegImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions Tests/test_file_jpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,19 @@ def test_save_modes_with_warnings(self):
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()

0 comments on commit 051a410

Please sign in to comment.