在處理略大檔案的圖片時,遇到python 程式顯示錯誤訊息:
/usr/local/lib/python3.7/site-packages/PIL/Image.py:2600: DecompressionBombWarning: Image size (103434240 pixels) exceeds limit of 89478485 pixels, could be decompression bomb DOS attack.
DecompressionBombWarning)
當圖片文件有超過89478485個像素點(若為16:9的圖片,其分辨率約為12608×7092)時使用PIL會觸發DecompressionBombWarning警告。
解法:可以通過設置Image.MAX_IMAGE_PIXELS來適當提高觸發警告的閾值,繼而強制加載。
from PIL import Image Image.MAX_IMAGE_PIXELS = 1000000000 im = Image.open(r'some_large_file.jpg')