diff --git a/src/libprs500/__init__.py b/src/libprs500/__init__.py index a0460e4c60..8c8336bc2c 100644 --- a/src/libprs500/__init__.py +++ b/src/libprs500/__init__.py @@ -13,7 +13,7 @@ ## with this program; if not, write to the Free Software Foundation, Inc., ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ''' E-book management software''' -__version__ = "0.3.67" +__version__ = "0.3.68" __docformat__ = "epytext" __author__ = "Kovid Goyal " __appname__ = 'libprs500' diff --git a/src/libprs500/ebooks/lrf/html/convert_from.py b/src/libprs500/ebooks/lrf/html/convert_from.py index 100a728db3..377fe486ca 100644 --- a/src/libprs500/ebooks/lrf/html/convert_from.py +++ b/src/libprs500/ebooks/lrf/html/convert_from.py @@ -789,10 +789,14 @@ def process_image(self, path, tag_css, width=None, height=None, dropcaps=False): def scale_image(width, height): pt = PersistentTemporaryFile(suffix='.jpeg') - im.resize((int(width), int(height)), PILImage.ANTIALIAS).convert('RGB').save(pt, 'JPEG') - pt.close() - self.scaled_images[path] = pt - return pt.name + try: + im.resize((int(width), int(height)), PILImage.ANTIALIAS).convert('RGB').save(pt, 'JPEG') + pt.close() + self.scaled_images[path] = pt + return pt.name + except IOError: # PIL chokes on interlaced PNG images + print >>sys.stderr, 'Unable to process interlaced PNG', path + return pheight = int(self.current_page.pageStyle.attrs['textheight']) pwidth = int(self.current_page.pageStyle.attrs['textwidth']) @@ -819,17 +823,22 @@ def scale_image(width, height): dc.append(Plot(im, xsize=ceil(width*factor), ysize=ceil(height*factor))) self.current_para.append(dc) return - + if not self.disable_autorotation and width > pwidth and width > height: pt = PersistentTemporaryFile(suffix='.jpeg') - im = im.rotate(90) - im.convert('RGB').save(pt, 'JPEG') - path = pt.name - pt.close() - self.rotated_images[path] = pt - width, height = im.size + try: + im = im.rotate(90) + im.convert('RGB').save(pt, 'JPEG') + path = pt.name + self.rotated_images[path] = pt + width, height = im.size + except IOError, err: # PIL chokes on interlaced PNG files and since auto-rotation is not critical we ignore the error + if self.verbose: + print >>sys.stderr, 'Unable to autorotate interlaced PNG', path + print >>sys.stderr, err + finally: + pt.close() - if height > pheight: corrf = pheight/(1.*height) width, height = floor(corrf*width), pheight-1