Skip to content

Commit

Permalink
Merge 634740c into f12febf
Browse files Browse the repository at this point in the history
  • Loading branch information
masterfool committed Aug 16, 2016
2 parents f12febf + 634740c commit 3c1afc2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions PIL/TiffImagePlugin.py
Expand Up @@ -1154,9 +1154,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(round(xres)), int(round(yres))
elif resunit == 3: # dots per centimeter. convert to dpi
self.info["dpi"] = xres * 2.54, yres * 2.54
self.info["dpi"] = int(round(xres * 2.54)), int(round(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 3c1afc2

Please sign in to comment.