mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-13 05:06:49 +03:00
Merge pull request #1113 from bpedersen2/master
Tiff: allow writing floating point tag values
This commit is contained in:
commit
b7bf299dad
|
@ -517,6 +517,15 @@ class ImageFileDirectory(collections.MutableMapping):
|
||||||
elif typ == 7:
|
elif typ == 7:
|
||||||
# untyped data
|
# untyped data
|
||||||
data = value = b"".join(value)
|
data = value = b"".join(value)
|
||||||
|
elif typ in (11, 12):
|
||||||
|
# float value
|
||||||
|
tmap = {11: 'f', 12: 'd'}
|
||||||
|
if not isinstance(value, tuple):
|
||||||
|
value = (value,)
|
||||||
|
a = array.array(tmap[typ], value)
|
||||||
|
if self.prefix != native_prefix:
|
||||||
|
a.byteswap()
|
||||||
|
data = a.tostring()
|
||||||
elif isStringType(value[0]):
|
elif isStringType(value[0]):
|
||||||
# string data
|
# string data
|
||||||
if isinstance(value, tuple):
|
if isinstance(value, tuple):
|
||||||
|
|
|
@ -16,10 +16,18 @@ class TestFileTiffMetadata(PillowTestCase):
|
||||||
img = hopper()
|
img = hopper()
|
||||||
|
|
||||||
textdata = "This is some arbitrary metadata for a text field"
|
textdata = "This is some arbitrary metadata for a text field"
|
||||||
|
floatdata = 12.345
|
||||||
|
doubledata = 67.89
|
||||||
|
|
||||||
info = TiffImagePlugin.ImageFileDirectory()
|
info = TiffImagePlugin.ImageFileDirectory()
|
||||||
|
|
||||||
info[tag_ids['ImageJMetaDataByteCounts']] = len(textdata)
|
info[tag_ids['ImageJMetaDataByteCounts']] = len(textdata)
|
||||||
info[tag_ids['ImageJMetaData']] = textdata
|
info[tag_ids['ImageJMetaData']] = textdata
|
||||||
|
info[tag_ids['RollAngle']] = floatdata
|
||||||
|
info.tagtype[tag_ids['RollAngle']] = 11
|
||||||
|
|
||||||
|
info[tag_ids['YawAngle']] = doubledata
|
||||||
|
info.tagtype[tag_ids['YawAngle']] = 12
|
||||||
|
|
||||||
f = self.tempfile("temp.tif")
|
f = self.tempfile("temp.tif")
|
||||||
|
|
||||||
|
@ -29,6 +37,9 @@ class TestFileTiffMetadata(PillowTestCase):
|
||||||
|
|
||||||
self.assertEqual(loaded.tag[50838], (len(textdata),))
|
self.assertEqual(loaded.tag[50838], (len(textdata),))
|
||||||
self.assertEqual(loaded.tag[50839], textdata)
|
self.assertEqual(loaded.tag[50839], textdata)
|
||||||
|
self.assertAlmostEqual(loaded.tag[tag_ids['RollAngle']][0], floatdata,
|
||||||
|
places=5)
|
||||||
|
self.assertAlmostEqual(loaded.tag[tag_ids['YawAngle']][0], doubledata)
|
||||||
|
|
||||||
def test_read_metadata(self):
|
def test_read_metadata(self):
|
||||||
img = Image.open('Tests/images/hopper_g4.tif')
|
img = Image.open('Tests/images/hopper_g4.tif')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user