This commit is contained in:
masterfool 2016-08-25 23:02:31 +00:00 committed by GitHub
commit 93b894a5ab
2 changed files with 16 additions and 2 deletions

View File

@ -1154,9 +1154,9 @@ class TiffImageFile(ImageFile.ImageFile):
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

View File

@ -470,6 +470,20 @@ class TestFileTiff(PillowTestCase):
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()