Merge pull request #213 from mattip/master

add tests and fix for issue 212
This commit is contained in:
Alex Clark ☺ 2013-05-11 15:37:04 -07:00
commit 6599df461b
2 changed files with 25 additions and 11 deletions

View File

@ -723,6 +723,10 @@ class TiffImageFile(ImageFile.ImageFile):
xres = getscalar(X_RESOLUTION, (1, 1))
yres = getscalar(Y_RESOLUTION, (1, 1))
if xres and not isinstance(xres, tuple):
xres = (xres, 1.)
if yres and not isinstance(yres, tuple):
yres = (yres, 1.)
if xres and yres:
xres = xres[0] / (xres[1] or 1)
yres = yres[0] / (yres[1] or 1)

View File

@ -60,4 +60,14 @@ def test_gimp_tiff():
])
assert_no_exception(lambda: im.load())
def test_xyres_tiff():
from PIL.TiffImagePlugin import X_RESOLUTION, Y_RESOLUTION
file = "Tests/images/pil168.tif"
im = Image.open(file)
assert isinstance(im.tag.tags[X_RESOLUTION][0], tuple)
assert isinstance(im.tag.tags[Y_RESOLUTION][0], tuple)
#Try to read a file where X,Y_RESOLUTION are ints
im.tag.tags[X_RESOLUTION] = (72,)
im.tag.tags[Y_RESOLUTION] = (72,)
im._setup()
assert_equal(im.info['dpi'], (72., 72.))