Fix #9286 (Paste cover fails in 0.7.48)

This commit is contained in:
Kovid Goyal 2011-03-05 07:44:38 -07:00
parent 1bef93de39
commit dec2f6aa14
2 changed files with 12 additions and 3 deletions

View File

@ -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.search_query_parser import saved_searches, set_saved_searches
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.formatter_functions import load_user_template_functions
@ -951,7 +951,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
if callable(getattr(data, 'read', None)):
data = data.read()
try:
data = minify_image(data, tweaks['maximum_cover_size'])
save_cover_data_to(data, path)
except (IOError, OSError):
time.sleep(0.2)

View File

@ -47,7 +47,7 @@ def normalize_format_name(fmt):
return fmt
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
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).
: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 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
@ -71,11 +74,18 @@ def save_cover_data_to(data, path, bgcolor='#ffffff', resize_to=None,
if resize_to is not None:
img.size = (resize_to[0], resize_to[1])
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():
canvas = create_canvas(img.size[0], img.size[1], bgcolor)
canvas.compose(img)
img = canvas
changed = True
if not changed:
changed = fmt != orig_fmt