From 0204733fd6935eb01680a332222167977aa697de Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 7 Oct 2013 23:03:50 -0700 Subject: [PATCH] Proper handling of both IFDs for libtiff usage --- PIL/TiffImagePlugin.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index 06a712b55..342dba36c 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -1071,11 +1071,13 @@ def _save(im, fp, filename): _fp = os.dup(fp.fileno()) blocklist = [STRIPOFFSETS, STRIPBYTECOUNTS, ROWSPERSTRIP, ICCPROFILE] # ICC Profile crashes. - atts = dict([(k,v) for (k,(v,)) in ifd.items() if k not in blocklist]) + + items = itertools.chain(getattr(im, 'ifd', {}).items(), ifd.items()) + atts = {} try: # pull in more bits from the original file, e.g x,y resolution # so that we can save(load('')) == original file. - for k,v in im.ifd.items(): + for k,v in items: if k not in atts and k not in blocklist: if type(v[0]) == tuple and len(v) > 1: # A tuple of more than one rational tuples @@ -1094,9 +1096,15 @@ def _save(im, fp, filename): if type(v) == str: atts[k] = v continue + if type(v) == unicode: + atts[k] = v.encode('ascii', errors='ignore') + continue - except: + except Exception, msg: # if we don't have an ifd here, just punt. + if Image.DEBUG: + print (msg) + #raise msg pass if Image.DEBUG: print (atts)