Handle case that cover size is smaller than thumbnail size

Update teststatus
This commit is contained in:
Ozzie Isaacs 2023-03-20 19:00:35 +01:00
parent 7ade4615a4
commit 224777f5e3
2 changed files with 1112 additions and 518 deletions

View File

@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
from shutil import copyfile, copyfileobj
from urllib.request import urlopen
from .. import constants
@ -188,14 +189,18 @@ class TaskGenerateCoverThumbnails(CalibreTask):
try:
stream = urlopen(web_content_link)
with Image(file=stream) as img:
filename = self.cache.get_cache_file_path(thumbnail.filename,
constants.CACHE_TYPE_THUMBNAILS)
height = get_resize_height(thumbnail.resolution)
if img.height > height:
width = get_resize_width(thumbnail.resolution, img.width, img.height)
img.resize(width=width, height=height, filter='lanczos')
img.format = thumbnail.format
filename = self.cache.get_cache_file_path(thumbnail.filename,
constants.CACHE_TYPE_THUMBNAILS)
img.save(filename=filename)
else:
with open(filename, 'rb') as fd:
copyfileobj(stream, fd)
except Exception as ex:
# Bubble exception to calling function
self.log.debug('Error generating thumbnail file: ' + str(ex))
@ -210,12 +215,15 @@ class TaskGenerateCoverThumbnails(CalibreTask):
with Image(filename=book_cover_filepath) as img:
height = get_resize_height(thumbnail.resolution)
filename = self.cache.get_cache_file_path(thumbnail.filename, constants.CACHE_TYPE_THUMBNAILS)
if img.height > height:
width = get_resize_width(thumbnail.resolution, img.width, img.height)
img.resize(width=width, height=height, filter='lanczos')
img.format = thumbnail.format
filename = self.cache.get_cache_file_path(thumbnail.filename, constants.CACHE_TYPE_THUMBNAILS)
img.save(filename=filename)
else:
# take cover as is
copyfile(book_cover_filepath, filename)
@property
def name(self):

File diff suppressed because it is too large Load Diff