From d98c90381f5e06705cd1293b4099159e14469f99 Mon Sep 17 00:00:00 2001 From: Jeffrey de Lange Date: Sat, 7 Dec 2013 17:13:05 +0100 Subject: [PATCH 1/2] Added check for when exif is None in adding pictures --- docx.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docx.py b/docx.py index 3cae9a7..95957eb 100755 --- a/docx.py +++ b/docx.py @@ -482,6 +482,9 @@ def picture(relationshiplist, picname, picdescription, pixelwidth=None, exif = image._getexif() except: exif = {} + + if exif is None: + exif = {} for tag, value in exif.items(): imageExif[TAGS.get(tag, tag)] = value From 94d7689de261325a7d94ed7200b8a256b1546daa Mon Sep 17 00:00:00 2001 From: Jeffrey de Lange Date: Sat, 7 Dec 2013 17:15:06 +0100 Subject: [PATCH 2/2] Updated example-makedocument.py to use the imagefiledict --- example-makedocument.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/example-makedocument.py b/example-makedocument.py index a2adf97..187e0a7 100755 --- a/example-makedocument.py +++ b/example-makedocument.py @@ -19,6 +19,9 @@ # Make a new document tree - this is the main part of a Word document document = newdocument() + + # Make a dict in which you will store image data + imagefiledict = {} # This xpath location is where most interesting content lives body = document.xpath('/w:document/w:body', namespaces=nsprefixes)[0] @@ -67,8 +70,9 @@ body.append(paragraph(point, style='ListBullet')) # Add an image - relationships, picpara = picture(relationships, 'image1.png', - 'This is a test description') + relationships, picpara, imagefiledict = picture(relationships, 'image1.png', + 'This is a test description', + imagefiledict=imagefiledict) body.append(picpara) # Search and replace @@ -109,5 +113,6 @@ # Save our document savedocx(document, coreprops, appprops, contenttypes, websettings, - wordrelationships, 'Welcome to the Python docx module.docx') + wordrelationships, 'Welcome to the Python docx module.docx' + imagefiledict=imagefiledict)