mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-03-13 04:55:49 +01:00
Workaround for missing mobi images.
This commit is contained in:
@@ -7,6 +7,7 @@ __copyright__ = '2012, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import shutil, os, re, struct, textwrap, io
|
import shutil, os, re, struct, textwrap, io
|
||||||
|
import logging
|
||||||
|
|
||||||
from lxml import html, etree
|
from lxml import html, etree
|
||||||
|
|
||||||
@@ -912,6 +913,8 @@ class MobiReader(object):
|
|||||||
try:
|
try:
|
||||||
save_cover_data_to(data, path, minify_to=(10000, 10000))
|
save_cover_data_to(data, path, minify_to=(10000, 10000))
|
||||||
except Exception:
|
except Exception:
|
||||||
|
logging.exception('Exception has been thrown during '
|
||||||
|
'transforming image')
|
||||||
continue
|
continue
|
||||||
self.image_names.append(os.path.basename(path))
|
self.image_names.append(os.path.basename(path))
|
||||||
return image_name_map
|
return image_name_map
|
||||||
|
|||||||
@@ -246,6 +246,14 @@ def save_cover_data_to(
|
|||||||
:param letterbox: If True, in addition to fit resize_to inside minify_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).
|
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:])
|
fmt = normalize_format_name(data_fmt if path is None else os.path.splitext(path)[1][1:])
|
||||||
if isinstance(data, QImage):
|
if isinstance(data, QImage):
|
||||||
img = data
|
img = data
|
||||||
@@ -254,6 +262,7 @@ def save_cover_data_to(
|
|||||||
img, orig_fmt = image_and_format_from_data(data)
|
img, orig_fmt = image_and_format_from_data(data)
|
||||||
orig_fmt = normalize_format_name(orig_fmt)
|
orig_fmt = normalize_format_name(orig_fmt)
|
||||||
changed = fmt != orig_fmt
|
changed = fmt != orig_fmt
|
||||||
|
|
||||||
if resize_to is not None:
|
if resize_to is not None:
|
||||||
changed = True
|
changed = True
|
||||||
img = img.scaled(resize_to[0], resize_to[1], Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
|
img = img.scaled(resize_to[0], resize_to[1], Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
|
||||||
|
|||||||
Reference in New Issue
Block a user