Skip to content

Commit

Permalink
Merge 9e56509 into f12febf
Browse files Browse the repository at this point in the history
  • Loading branch information
masterfool committed Aug 16, 2016
2 parents f12febf + 9e56509 commit 4e35e5b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions PIL/TiffImagePlugin.py
Expand Up @@ -52,6 +52,7 @@

import io
import itertools
import math
import os
import struct
import sys
Expand Down Expand Up @@ -1154,9 +1155,9 @@ def _setup(self):
if xres and yres:
resunit = self.tag_v2.get(RESOLUTION_UNIT, 1)
if resunit == 2: # dots per inch
self.info["dpi"] = xres, yres
self.info["dpi"] = int(math.ceil(xres)), int(math.ceil(yres))
elif resunit == 3: # dots per centimeter. convert to dpi
self.info["dpi"] = xres * 2.54, yres * 2.54
self.info["dpi"] = int(math.ceil(xres * 2.54)), int(math.ceil(yres * 2.54))
else: # No absolute unit of measurement
self.info["resolution"] = xres, yres

Expand Down
14 changes: 14 additions & 0 deletions Tests/test_file_tiff.py
Expand Up @@ -470,6 +470,20 @@ def test_open_tiff_uint16(self):
im = Image.open(infile)
self.assertEqual(im.getpixel((0, 0)), pixel_value)

def test_save_tiff_with_dpi(self):

outfile = self.tempfile("temp.tif")

infile = "Tests/images/hopper.tif"
im = Image.open(infile)

im.save(outfile, 'JPEG', dpi=im.info['dpi'])

reloaded = Image.open(outfile)
reloaded.load()

self.assertEqual(im.info['dpi'], reloaded.info['dpi'])


if __name__ == '__main__':
unittest.main()

0 comments on commit 4e35e5b

Please sign in to comment.