diff --git a/ebook_converter/ebooks/mobi/reader/mobi6.py b/ebook_converter/ebooks/mobi/reader/mobi6.py index 4f1ddf7..15d0cf6 100644 --- a/ebook_converter/ebooks/mobi/reader/mobi6.py +++ b/ebook_converter/ebooks/mobi/reader/mobi6.py @@ -7,6 +7,7 @@ __copyright__ = '2012, Kovid Goyal ' __docformat__ = 'restructuredtext en' import shutil, os, re, struct, textwrap, io +import logging from lxml import html, etree @@ -912,6 +913,8 @@ class MobiReader(object): try: save_cover_data_to(data, path, minify_to=(10000, 10000)) except Exception: + logging.exception('Exception has been thrown during ' + 'transforming image') continue self.image_names.append(os.path.basename(path)) return image_name_map diff --git a/ebook_converter/utils/img.py b/ebook_converter/utils/img.py index 69e4e0d..46f24f0 100644 --- a/ebook_converter/utils/img.py +++ b/ebook_converter/utils/img.py @@ -246,6 +246,14 @@ def save_cover_data_to( :param letterbox: If True, in addition to fit resize_to inside minify_to, the image will be letterboxed (i.e., centered on a black background). ''' + # TODO(gryf): analyze case by case, why we need all this crap down below, + # and why QImage object is used, instead simply do the transformation with + # pillow. + with open(path, 'wb') as fobj: + fobj.write(data) + return + + fmt = normalize_format_name(data_fmt if path is None else os.path.splitext(path)[1][1:]) if isinstance(data, QImage): img = data @@ -254,6 +262,7 @@ def save_cover_data_to( img, orig_fmt = image_and_format_from_data(data) orig_fmt = normalize_format_name(orig_fmt) changed = fmt != orig_fmt + if resize_to is not None: changed = True img = img.scaled(resize_to[0], resize_to[1], Qt.IgnoreAspectRatio, Qt.SmoothTransformation)