From 46a827567a98e4ce2610c33c2e2eb1991b9eea67 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 1 Apr 2008 19:59:04 +0000 Subject: [PATCH] Fix #614 --- src/libprs500/ebooks/lrf/html/convert_from.py | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/libprs500/ebooks/lrf/html/convert_from.py b/src/libprs500/ebooks/lrf/html/convert_from.py index e219283938..142e2a46a6 100644 --- a/src/libprs500/ebooks/lrf/html/convert_from.py +++ b/src/libprs500/ebooks/lrf/html/convert_from.py @@ -1724,18 +1724,22 @@ def process_file(path, options, logger=None): width, height = pwidth, int(corrf*height) scaled, width, height = fit_image(width, height, pwidth, pheight) - cim = im.resize((width, height), PILImage.BICUBIC).convert('RGB') if \ - scaled else im - cf = PersistentTemporaryFile(prefix=__appname__+"_", suffix=".jpg") - cf.close() - cim.save(cf.name) - options.cover = cf.name - - tim = im.resize((int(0.75*th), th), PILImage.ANTIALIAS).convert('RGB') - tf = PersistentTemporaryFile(prefix=__appname__+'_', suffix=".jpg") - tf.close() - tim.save(tf.name) - tpath = tf.name + try: + cim = im.resize((width, height), PILImage.BICUBIC).convert('RGB') if \ + scaled else im + cf = PersistentTemporaryFile(prefix=__appname__+"_", suffix=".jpg") + cf.close() + cim.save(cf.name) + options.cover = cf.name + + tim = im.resize((int(0.75*th), th), PILImage.ANTIALIAS).convert('RGB') + tf = PersistentTemporaryFile(prefix=__appname__+'_', suffix=".jpg") + tf.close() + tim.save(tf.name) + tpath = tf.name + except IOError, err: # PIL sometimes fails, for example on interlaced PNG files + logger.warn(_('Could not read cover image: %s'), err) + options.cover = None else: raise ConversionError, _('Cannot read from: %s')% (options.cover,)