mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-02 04:03:33 +03:00
In a twisty maze of bytes, text and arbitrary metadata, py2 and py3. New IFD is putting textdata in type7 metadata and returning bytes, old one put it in type 2 string and returned a string. This may be an issue
This commit is contained in:
parent
426c9d8fc2
commit
b1fdff4034
|
@ -361,7 +361,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
||||||
self.tagtype[tag] = 2
|
self.tagtype[tag] = 2
|
||||||
|
|
||||||
if self.tagtype[tag] == 7 and bytes is not str:
|
if self.tagtype[tag] == 7 and bytes is not str:
|
||||||
values = [value.encode("ascii") if isinstance(value, str) else value
|
values = [value.encode("ascii",'replace') if isinstance(value, str) else value
|
||||||
for value in values]
|
for value in values]
|
||||||
values = tuple(info.cvt_enum(value) for value in values)
|
values = tuple(info.cvt_enum(value) for value in values)
|
||||||
if info.length == 1:
|
if info.length == 1:
|
||||||
|
|
|
@ -19,28 +19,31 @@ class TestFileTiffMetadata(PillowTestCase):
|
||||||
|
|
||||||
basetextdata = "This is some arbitrary metadata for a text field"
|
basetextdata = "This is some arbitrary metadata for a text field"
|
||||||
textdata = basetextdata + " \xff"
|
textdata = basetextdata + " \xff"
|
||||||
|
reloaded_textdata = basetextdata.encode('ascii') + b" ?"
|
||||||
floatdata = 12.345
|
floatdata = 12.345
|
||||||
doubledata = 67.89
|
doubledata = 67.89
|
||||||
info = TiffImagePlugin.ImageFileDirectory()
|
info = TiffImagePlugin.ImageFileDirectory()
|
||||||
|
|
||||||
info[tag_ids['ImageJMetaDataByteCounts']] = len(textdata)
|
info[tag_ids['ImageJMetaDataByteCounts']] = len(reloaded_textdata)
|
||||||
info[tag_ids['ImageJMetaData']] = textdata
|
info[tag_ids['ImageJMetaData']] = textdata
|
||||||
info[tag_ids['RollAngle']] = floatdata
|
info[tag_ids['RollAngle']] = floatdata
|
||||||
info.tagtype[tag_ids['RollAngle']] = 11
|
info.tagtype[tag_ids['RollAngle']] = 11
|
||||||
info[tag_ids['YawAngle']] = doubledata
|
info[tag_ids['YawAngle']] = doubledata
|
||||||
info.tagtype[tag_ids['YawAngle']] = 12
|
info.tagtype[tag_ids['YawAngle']] = 12
|
||||||
|
|
||||||
|
print(info.tagtype)
|
||||||
|
|
||||||
f = self.tempfile("temp.tif")
|
f = self.tempfile("temp.tif")
|
||||||
|
|
||||||
img.save(f, tiffinfo=info)
|
img.save(f, tiffinfo=info)
|
||||||
|
|
||||||
loaded = Image.open(f)
|
loaded = Image.open(f)
|
||||||
|
|
||||||
self.assertEqual(loaded.tag[50838], (len(basetextdata + " ?"),))
|
self.assertEqual(loaded.tag[50838], (len(reloaded_textdata),))
|
||||||
self.assertEqual(loaded.tag_v2[50838], len(basetextdata + " ?"))
|
self.assertEqual(loaded.tag_v2[50838], len(reloaded_textdata))
|
||||||
|
|
||||||
self.assertEqual(loaded.tag[50839], basetextdata + " ?")
|
self.assertEqual(loaded.tag[50839], reloaded_textdata)
|
||||||
self.assertEqual(loaded.tag_v2[50839], basetextdata + " ?")
|
self.assertEqual(loaded.tag_v2[50839], reloaded_textdata)
|
||||||
|
|
||||||
|
|
||||||
loaded_float = loaded.tag[tag_ids['RollAngle']][0]
|
loaded_float = loaded.tag[tag_ids['RollAngle']][0]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user