mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-16 18:24:45 +03:00
Store TIFF DPI as integer
This commit is contained in:
parent
f12febf3a9
commit
9e5650914c
|
@ -52,6 +52,7 @@ from numbers import Number, Rational
|
||||||
|
|
||||||
import io
|
import io
|
||||||
import itertools
|
import itertools
|
||||||
|
import math
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
|
@ -1154,9 +1155,9 @@ class TiffImageFile(ImageFile.ImageFile):
|
||||||
if xres and yres:
|
if xres and yres:
|
||||||
resunit = self.tag_v2.get(RESOLUTION_UNIT, 1)
|
resunit = self.tag_v2.get(RESOLUTION_UNIT, 1)
|
||||||
if resunit == 2: # dots per inch
|
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
|
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
|
else: # No absolute unit of measurement
|
||||||
self.info["resolution"] = xres, yres
|
self.info["resolution"] = xres, yres
|
||||||
|
|
||||||
|
|
|
@ -470,6 +470,20 @@ class TestFileTiff(PillowTestCase):
|
||||||
im = Image.open(infile)
|
im = Image.open(infile)
|
||||||
self.assertEqual(im.getpixel((0, 0)), pixel_value)
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user