1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-02-16 05:55:54 +01:00

Workaround for missing mobi images.

This commit is contained in:
2020-04-13 11:34:07 +02:00
parent 8a04ca71a9
commit 860044904d
2 changed files with 12 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ __copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
__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

View File

@@ -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)