From 33cd1642f83cbbf0fcad1cfeaef00a60f5d07e4e Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Tue, 5 Sep 2023 10:29:34 -0500 Subject: [PATCH] Explicitly call set_image_allocation_limit() for larger image buffer and error on 0x0 image from image_and_format_from_data() --- fanficfare/story.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/fanficfare/story.py b/fanficfare/story.py index a634dc9b..a646d273 100644 --- a/fanficfare/story.py +++ b/fanficfare/story.py @@ -57,10 +57,16 @@ imagetypes = { try: from calibre.utils.img import ( Canvas, image_from_data, image_and_format_from_data, image_to_data, - image_has_transparent_pixels, grayscale_image, resize_image + image_has_transparent_pixels, grayscale_image, resize_image, + set_image_allocation_limit ) convtype = {'jpg':'JPG', 'png':'PNG'} + # Calibre function that increases qt image processing buffer size + # for larger than 32 megapixel images. At time of writing, + # Calibre sets it up to 256 megapixel images + set_image_allocation_limit() + def get_image_size(data): img = image_from_data(data) size = img.size() @@ -83,6 +89,9 @@ try: nwidth, nheight = sizes scaled, nwidth, nheight = fit_image(owidth, oheight, nwidth, nheight) + if (0,0) == (owidth,oheight): + raise exceptions.RejectImage("Calibre image processing returned 0x0 image\nSee https://github.com/JimmXinu/FanFicFare/issues/997 for one possible reason.") + if scaled: img = resize_image(img, nwidth, nheight) export = True