From f551cde996417d38335f8174fd69c5def58ddf17 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 22 Mar 2012 14:13:09 +0530 Subject: [PATCH] RTF Output: Ignore corrupted images in the input document, instead of erroring out. Fixes #959600 (Corrupt png prevents conversion) --- src/calibre/ebooks/rtf/rtfml.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/rtf/rtfml.py b/src/calibre/ebooks/rtf/rtfml.py index 0fdc6cad1d..a7fa9eb62a 100644 --- a/src/calibre/ebooks/rtf/rtfml.py +++ b/src/calibre/ebooks/rtf/rtfml.py @@ -161,8 +161,14 @@ class RTFMLizer(object): for item in self.oeb_book.manifest: if item.media_type in OEB_RASTER_IMAGES: src = os.path.basename(item.href) - data, width, height = self.image_to_hexstring(item.data) - text = text.replace('SPECIAL_IMAGE-%s-REPLACE_ME' % src, '\n\n{\\*\\shppict{\\pict\\picw%i\\pich%i\\jpegblip \n%s\n}}\n\n' % (width, height, data)) + try: + data, width, height = self.image_to_hexstring(item.data) + except: + self.log.warn('Image %s is corrupted, ignoring'%item.href) + repl = '\n\n' + else: + repl = '\n\n{\\*\\shppict{\\pict\\picw%i\\pich%i\\jpegblip \n%s\n}}\n\n' % (width, height, data) + text = text.replace('SPECIAL_IMAGE-%s-REPLACE_ME' % src, repl) return text def image_to_hexstring(self, data):