DOCX Output: Ignore corrupted images in the input instead of erroring out on them.

This commit is contained in:
Kovid Goyal 2015-10-11 22:35:48 +05:30
parent 23a6c43552
commit 2ba85a0869

View File

@ -49,7 +49,12 @@ class ImagesManager(object):
item = self.oeb.manifest.hrefs.get(href) item = self.oeb.manifest.hrefs.get(href)
if item is None or not isinstance(item.data, bytes): if item is None or not isinstance(item.data, bytes):
return return
width, height, fmt = identify_data(item.data) try:
width, height, fmt = identify_data(item.data)
except Exception:
self.log.warning('Replacing corrupted image with blank: %s' % href)
item.data = I('blank.png', data=True, allow_user_override=False)
width, height, fmt = identify_data(item.data)
image_fname = 'media/' + self.create_filename(href, fmt) image_fname = 'media/' + self.create_filename(href, fmt)
image_rid = self.document_relationships.add_image(image_fname) image_rid = self.document_relationships.add_image(image_fname)
self.images[href] = Image(image_rid, image_fname, width, height, fmt, item) self.images[href] = Image(image_rid, image_fname, width, height, fmt, item)