PIL Open image, causing DecompressionBombError - Image size (191720704 pixels) exceeds limit of 178956970 pixels, could be decompression bomb DOS attack

Was facing an issue in classification model trained on fastai’s timm library (convnext model).

I was running images in batches on a classification model for batch inference. But due to 1 image, entire batch is failing. The classification model when trained was trained on preprocessed images, by applying transformations on image size = 224.
When the particular image is passed for inference, it shows this error and entire batch fails.

Error:
“Image size (191720704 pixels) exceeds limit of 178956970 pixels, could be decompression bomb DOS attack.”

Why is this error showing then?

Had preprocessed the images when I trained the model, by providing image size to be 224.

I’d like to respect the limit and not increase the limit (as described here: Pillow in Python won’t let me open image (“exceeds limit”))

How can I load it in a way that the resolution is lowered just below the limit and the lower resolution image is referenced in img without causing any error.

It’d be great to have a Python solution but if not, any other solution will work too.