mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
rewrite of #1416 working
This commit is contained in:
parent
b1fdff4034
commit
0c35194167
|
@ -17,34 +17,50 @@ class TestFileTiffMetadata(PillowTestCase):
|
||||||
|
|
||||||
img = hopper()
|
img = hopper()
|
||||||
|
|
||||||
|
# Behaviour change:
|
||||||
|
# Pre ifd rewrite, ImageJMetaData was being written as a string(2),
|
||||||
|
# Post ifd rewrite, it's defined as arbitrary bytes(7). It should
|
||||||
|
# roundtrip with the actual bytes, rather than stripped text
|
||||||
|
# of the premerge tests.
|
||||||
|
#
|
||||||
|
# For text items, we still have to decode('ascii','replace') because
|
||||||
|
# the tiff file format can't take 8 bit bytes in that field.
|
||||||
|
|
||||||
basetextdata = "This is some arbitrary metadata for a text field"
|
basetextdata = "This is some arbitrary metadata for a text field"
|
||||||
textdata = basetextdata + " \xff"
|
bindata = basetextdata.encode('ascii') + b" \xff"
|
||||||
reloaded_textdata = basetextdata.encode('ascii') + b" ?"
|
textdata = basetextdata + " " + chr(255)
|
||||||
|
reloaded_textdata = basetextdata + " ?"
|
||||||
floatdata = 12.345
|
floatdata = 12.345
|
||||||
doubledata = 67.89
|
doubledata = 67.89
|
||||||
info = TiffImagePlugin.ImageFileDirectory()
|
info = TiffImagePlugin.ImageFileDirectory()
|
||||||
|
|
||||||
info[tag_ids['ImageJMetaDataByteCounts']] = len(reloaded_textdata)
|
ImageJMetaData = tag_ids['ImageJMetaData']
|
||||||
info[tag_ids['ImageJMetaData']] = textdata
|
ImageJMetaDataByteCounts = tag_ids['ImageJMetaDataByteCounts']
|
||||||
|
ImageDescription = tag_ids['ImageDescription']
|
||||||
|
|
||||||
|
info[ImageJMetaDataByteCounts] = len(bindata)
|
||||||
|
info[ImageJMetaData] = bindata
|
||||||
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)
|
info[ImageDescription] = textdata
|
||||||
|
|
||||||
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(reloaded_textdata),))
|
self.assertEqual(loaded.tag[ImageJMetaDataByteCounts], (len(bindata),))
|
||||||
self.assertEqual(loaded.tag_v2[50838], len(reloaded_textdata))
|
self.assertEqual(loaded.tag_v2[ImageJMetaDataByteCounts], len(bindata))
|
||||||
|
|
||||||
self.assertEqual(loaded.tag[50839], reloaded_textdata)
|
self.assertEqual(loaded.tag[ImageJMetaData], bindata)
|
||||||
self.assertEqual(loaded.tag_v2[50839], reloaded_textdata)
|
self.assertEqual(loaded.tag_v2[ImageJMetaData], bindata)
|
||||||
|
|
||||||
|
self.assertEqual(loaded.tag[ImageDescription], (reloaded_textdata,))
|
||||||
|
self.assertEqual(loaded.tag_v2[ImageDescription], reloaded_textdata)
|
||||||
|
|
||||||
loaded_float = loaded.tag[tag_ids['RollAngle']][0]
|
loaded_float = loaded.tag[tag_ids['RollAngle']][0]
|
||||||
self.assertAlmostEqual(loaded_float, floatdata, places=5)
|
self.assertAlmostEqual(loaded_float, floatdata, places=5)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user