From ff1ee01b3b2aabbad2cf4859e30bc70ec8317f0f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Dec 2021 08:06:32 +0530 Subject: [PATCH] py310: Fix #1954951 [manual trimming of cover throws exception w/ python 3.10](https://bugs.launchpad.net/calibre/+bug/1954951) --- src/calibre/gui2/tweak_book/editor/canvas.py | 2 +- src/calibre/utils/img.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/calibre/gui2/tweak_book/editor/canvas.py b/src/calibre/gui2/tweak_book/editor/canvas.py index c5075ce2fc..34f43c82e2 100644 --- a/src/calibre/gui2/tweak_book/editor/canvas.py +++ b/src/calibre/gui2/tweak_book/editor/canvas.py @@ -97,7 +97,7 @@ class Trim(Command): img = canvas.current_image target = canvas.target sr = canvas.selection_state.rect - return img.copy(*get_selection_rect(img, sr, target)) + return img.copy(*map(int, get_selection_rect(img, sr, target))) class AutoTrim(Trim): diff --git a/src/calibre/utils/img.py b/src/calibre/utils/img.py index 0652b55fad..8aacf17ca0 100644 --- a/src/calibre/utils/img.py +++ b/src/calibre/utils/img.py @@ -296,9 +296,9 @@ def blend_on_canvas(img, width, height, bgcolor='#ffffff'): w, h = img.width(), img.height() scaled, nw, nh = fit_image(w, h, width, height) if scaled: - img = img.scaled(nw, nh, Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation) + img = img.scaled(int(nw), int(nh), Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation) w, h = nw, nh - canvas = QImage(width, height, QImage.Format.Format_RGB32) + canvas = QImage(int(width), int(height), QImage.Format.Format_RGB32) canvas.fill(QColor(bgcolor)) overlay_image(img, canvas, (width - w)//2, (height - h)//2) return canvas @@ -307,7 +307,7 @@ def blend_on_canvas(img, width, height, bgcolor='#ffffff'): class Canvas: def __init__(self, width, height, bgcolor='#ffffff'): - self.img = QImage(width, height, QImage.Format.Format_RGB32) + self.img = QImage(int(width), int(height), QImage.Format.Format_RGB32) self.img.fill(QColor(bgcolor)) def __enter__(self): @@ -326,7 +326,7 @@ class Canvas: def create_canvas(width, height, bgcolor='#ffffff'): 'Create a blank canvas of the specified size and color ' - img = QImage(width, height, QImage.Format.Format_RGB32) + img = QImage(int(width), int(height), QImage.Format.Format_RGB32) img.fill(QColor(bgcolor)) return img @@ -363,7 +363,7 @@ def add_borders_to_image(img, left=0, top=0, right=0, bottom=0, border_color='#f img = image_from_data(img) if not (left > 0 or right > 0 or top > 0 or bottom > 0): return img - canvas = QImage(img.width() + left + right, img.height() + top + bottom, QImage.Format.Format_RGB32) + canvas = QImage(int(img.width() + left + right), int(img.height() + top + bottom), QImage.Format.Format_RGB32) canvas.fill(QColor(border_color)) overlay_image(img, canvas, left, top) return canvas @@ -376,7 +376,7 @@ def remove_borders_from_image(img, fuzz=None): absolute intensity units). Default is from a tweak whose default value is 10. ''' fuzz = tweaks['cover_trim_fuzz_value'] if fuzz is None else fuzz img = image_from_data(img) - ans = imageops.remove_borders(img, max(0, fuzz)) + ans = imageops.remove_borders(img, int(max(0, fuzz))) return ans if ans.size() != img.size() else img # }}} @@ -432,7 +432,7 @@ def crop_image(img, x, y, width, height): img = image_from_data(img) width = min(width, img.width() - x) height = min(height, img.height() - y) - return img.copy(x, y, width, height) + return img.copy(int(x), int(y), int(width), int(height)) # }}}