mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 02:36:17 +03:00
Write round trip for rationals, including nan value
This commit is contained in:
parent
48e4e0722e
commit
3ac9396e8c
|
@ -497,11 +497,13 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
|||
values = [value] if isinstance(value, basetypes) else value
|
||||
|
||||
if tag not in self.tagtype:
|
||||
try:
|
||||
if info.type:
|
||||
self.tagtype[tag] = info.type
|
||||
except KeyError:
|
||||
else:
|
||||
self.tagtype[tag] = 7
|
||||
if all(isinstance(v, int) for v in values):
|
||||
if all(isinstance(v, IFDRational) for v in values):
|
||||
self.tagtype[tag] = 5
|
||||
elif all(isinstance(v, int) for v in values):
|
||||
if all(v < 2 ** 16 for v in values):
|
||||
self.tagtype[tag] = 3
|
||||
else:
|
||||
|
|
|
@ -23,7 +23,7 @@ from collections import namedtuple
|
|||
class TagInfo(namedtuple("_TagInfo", "value name type length enum")):
|
||||
__slots__ = []
|
||||
|
||||
def __new__(cls, value=None, name="unknown", type=4, length=0, enum=None):
|
||||
def __new__(cls, value=None, name="unknown", type=None, length=0, enum=None):
|
||||
return super(TagInfo, cls).__new__(
|
||||
cls, value, name, type, length, enum or {})
|
||||
|
||||
|
|
|
@ -185,6 +185,20 @@ class TestFileTiffMetadata(PillowTestCase):
|
|||
self.assertEqual(im.tag_v2.tagtype[34675], 1)
|
||||
self.assertTrue(im.info['icc_profile'])
|
||||
|
||||
def test_exif_div_zero(self):
|
||||
im = hopper()
|
||||
info = TiffImagePlugin.ImageFileDirectory_v2()
|
||||
info[41988] = TiffImagePlugin.IFDRational(0,0)
|
||||
|
||||
out = self.tempfile('temp.tiff')
|
||||
im.save(out, tiffinfo=info, compression='raw')
|
||||
|
||||
reloaded = Image.open(out)
|
||||
self.assertEqual(0, reloaded.tag_v2[41988][0].numerator)
|
||||
self.assertEqual(0, reloaded.tag_v2[41988][0].denominator)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
from __future__ import print_function
|
||||
|
||||
from helper import PillowTestCase
|
||||
from helper import PillowTestCase, hopper
|
||||
|
||||
from PIL import TiffImagePlugin, Image
|
||||
from PIL.TiffImagePlugin import IFDRational
|
||||
|
||||
from fractions import Fraction
|
||||
|
@ -44,3 +45,17 @@ class Test_IFDRational(PillowTestCase):
|
|||
self.assert_(xres and 1)
|
||||
self.assert_(xres and yres)
|
||||
|
||||
|
||||
def test_ifd_rational_save(self):
|
||||
for libtiff in (True, False):
|
||||
TiffImagePlugin.WRITE_LIBTIFF = libtiff
|
||||
|
||||
im = hopper()
|
||||
out = self.tempfile('temp.tiff')
|
||||
res = IFDRational(301,1)
|
||||
im.save(out, dpi=(res,res), compression='raw')
|
||||
|
||||
reloaded = Image.open(out)
|
||||
self.assertEqual(float(IFDRational(301,1)),
|
||||
float(reloaded.tag_v2[282]))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user