解决Pillow报错 Image size (XXX pixels) exceeds limit of 178956970 pixels, could be decompression
1 报错代码
PIL.Image.DecompressionBombError: Image size (244186200 pixels) exceeds limit of 178956970 pixels, could be decompression bomb DOS attack.
2 报错原因
原因即图片过大,超过178956970 pixels
3 解决方法
最初查到的解决方法是在导入ImageFile时添加以下代码
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
运行后还是报错。
最终解决方法为
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
Image.MAX_IMAGE_PIXELS = None