Explicitly call set_image_allocation_limit() for larger image buffer and error on 0x0 image from image_and_format_from_data()

This commit is contained in:
Jim Miller 2023-09-05 10:29:34 -05:00
parent 63ec69f9f2
commit 33cd1642f8

View file

@ -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