mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Fix #9286 (Paste cover fails in 0.7.48)
This commit is contained in:
parent
1bef93de39
commit
dec2f6aa14
@ -37,7 +37,7 @@ from calibre.utils.config import prefs, tweaks, from_json, to_json
|
|||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from calibre.utils.search_query_parser import saved_searches, set_saved_searches
|
from calibre.utils.search_query_parser import saved_searches, set_saved_searches
|
||||||
from calibre.ebooks import BOOK_EXTENSIONS, check_ebook_format
|
from calibre.ebooks import BOOK_EXTENSIONS, check_ebook_format
|
||||||
from calibre.utils.magick.draw import minify_image, save_cover_data_to
|
from calibre.utils.magick.draw import save_cover_data_to
|
||||||
from calibre.utils.recycle_bin import delete_file, delete_tree
|
from calibre.utils.recycle_bin import delete_file, delete_tree
|
||||||
from calibre.utils.formatter_functions import load_user_template_functions
|
from calibre.utils.formatter_functions import load_user_template_functions
|
||||||
|
|
||||||
@ -951,7 +951,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
if callable(getattr(data, 'read', None)):
|
if callable(getattr(data, 'read', None)):
|
||||||
data = data.read()
|
data = data.read()
|
||||||
try:
|
try:
|
||||||
data = minify_image(data, tweaks['maximum_cover_size'])
|
|
||||||
save_cover_data_to(data, path)
|
save_cover_data_to(data, path)
|
||||||
except (IOError, OSError):
|
except (IOError, OSError):
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
@ -47,7 +47,7 @@ def normalize_format_name(fmt):
|
|||||||
return fmt
|
return fmt
|
||||||
|
|
||||||
def save_cover_data_to(data, path, bgcolor='#ffffff', resize_to=None,
|
def save_cover_data_to(data, path, bgcolor='#ffffff', resize_to=None,
|
||||||
return_data=False, compression_quality=90):
|
return_data=False, compression_quality=90, minify_to=None):
|
||||||
'''
|
'''
|
||||||
Saves image in data to path, in the format specified by the path
|
Saves image in data to path, in the format specified by the path
|
||||||
extension. Removes any transparency. If there is no transparency and no
|
extension. Removes any transparency. If there is no transparency and no
|
||||||
@ -60,6 +60,9 @@ def save_cover_data_to(data, path, bgcolor='#ffffff', resize_to=None,
|
|||||||
compression (lossless).
|
compression (lossless).
|
||||||
:param bgcolor: The color for transparent pixels. Must be specified in hex.
|
:param bgcolor: The color for transparent pixels. Must be specified in hex.
|
||||||
:param resize_to: A tuple (width, height) or None for no resizing
|
:param resize_to: A tuple (width, height) or None for no resizing
|
||||||
|
:param minify_to: A tuple (width, height) to specify target size. The image
|
||||||
|
will be resized to fit into this target size. If None the value from the
|
||||||
|
tweak is used.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
changed = False
|
changed = False
|
||||||
@ -71,11 +74,18 @@ def save_cover_data_to(data, path, bgcolor='#ffffff', resize_to=None,
|
|||||||
if resize_to is not None:
|
if resize_to is not None:
|
||||||
img.size = (resize_to[0], resize_to[1])
|
img.size = (resize_to[0], resize_to[1])
|
||||||
changed = True
|
changed = True
|
||||||
|
owidth, oheight = img.size
|
||||||
|
nwidth, nheight = tweaks['maximum_cover_size'] if minify_to is None else minify_to
|
||||||
|
scaled, nwidth, nheight = fit_image(owidth, oheight, nwidth, nheight)
|
||||||
|
if scaled:
|
||||||
|
img.size = (nwidth, nheight)
|
||||||
|
changed = True
|
||||||
if img.has_transparent_pixels():
|
if img.has_transparent_pixels():
|
||||||
canvas = create_canvas(img.size[0], img.size[1], bgcolor)
|
canvas = create_canvas(img.size[0], img.size[1], bgcolor)
|
||||||
canvas.compose(img)
|
canvas.compose(img)
|
||||||
img = canvas
|
img = canvas
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
if not changed:
|
if not changed:
|
||||||
changed = fmt != orig_fmt
|
changed = fmt != orig_fmt
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user