From 34743e4807c153f0821852d196b976567412154d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 17 Feb 2024 10:10:48 +0530 Subject: [PATCH] Fix #2054125 [ValueError: Failed to export image as JPEG with error: Image is empty](https://bugs.launchpad.net/calibre/+bug/2054125) --- src/calibre/utils/img.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/calibre/utils/img.py b/src/calibre/utils/img.py index 11bfc5b157..a420700f94 100644 --- a/src/calibre/utils/img.py +++ b/src/calibre/utils/img.py @@ -272,7 +272,12 @@ def save_cover_data_to( changed = True img = img.scaled(int(resize_to[0]), int(resize_to[1]), Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation) owidth, oheight = img.width(), img.height() - nwidth, nheight = tweaks['maximum_cover_size'] if minify_to is None else minify_to + if minify_to is None: + nwidth, nheight = tweaks['maximum_cover_size'] + nwidth, nheight = max(1, nwidth), max(1, nheight) + else: + nwidth, nheight = minify_to + if letterbox: img = blend_on_canvas(img, nwidth, nheight, bgcolor=letterbox_color) # Check if we were minified