better handling of unicode, rational tuples

This commit is contained in:
wiredfool 2013-10-07 23:02:59 -07:00
parent 350cc702f1
commit e6c8e5abec

View File

@ -482,6 +482,9 @@ class ImageFileDirectory(collections.MutableMapping):
if tag in self.tagtype: if tag in self.tagtype:
typ = self.tagtype[tag] typ = self.tagtype[tag]
if Image.DEBUG:
print ("Tag %s, Type: %s, Value: %s" % (tag, typ, value))
if typ == 1: if typ == 1:
# byte data # byte data
if isinstance(value, tuple): if isinstance(value, tuple):
@ -491,7 +494,7 @@ 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 isinstance(value[0], str): elif type(value[0]) in (str, unicode):
# string data # string data
if isinstance(value, tuple): if isinstance(value, tuple):
value = value[-1] value = value[-1]
@ -508,9 +511,12 @@ class ImageFileDirectory(collections.MutableMapping):
if tag == STRIPOFFSETS: if tag == STRIPOFFSETS:
stripoffsets = len(directory) stripoffsets = len(directory)
typ = 4 # to avoid catch-22 typ = 4 # to avoid catch-22
elif tag in (X_RESOLUTION, Y_RESOLUTION): elif tag in (X_RESOLUTION, Y_RESOLUTION) or typ==5:
# identify rational data fields # identify rational data fields
typ = 5 typ = 5
# UNDONE -- could be multiple rational tuples.
if isinstance(value[0], tuple):
value = value[-1]
elif not typ: elif not typ:
typ = 3 typ = 3
for v in value: for v in value: