RTF Output: Ignore corrupted images in the input document, instead of erroring out. Fixes #959600 (Corrupt png prevents conversion)

This commit is contained in:
Kovid Goyal 2012-03-22 14:13:09 +05:30
parent bfff783d1e
commit f551cde996

View File

@ -161,8 +161,14 @@ class RTFMLizer(object):
for item in self.oeb_book.manifest: for item in self.oeb_book.manifest:
if item.media_type in OEB_RASTER_IMAGES: if item.media_type in OEB_RASTER_IMAGES:
src = os.path.basename(item.href) src = os.path.basename(item.href)
try:
data, width, height = self.image_to_hexstring(item.data) 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)) 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 return text
def image_to_hexstring(self, data): def image_to_hexstring(self, data):