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 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)