如何使用 PIL 压缩大图像?

时间:2021-05-27 21:03:21

标签: python image python-imaging-library

我正在尝试使用 PIL 和 Python 压缩大尺寸图像。

典型流程不起作用。示例代码如下:

from PIL import Image
image = Image.open('415_2000_6in.tiff')
new_image = image.resize((200, 200), Image.ANTIALIAS)

错误为 Image size exceeds limit - 如下所示。还有其他选项可以压缩我的图片吗?

Traceback (most recent call last):
  File "C:/Users/kundemj/Desktop/2021-0087/main.py", line 13, in <module>
    image = Image.open('415_2000_6in.tiff')
  File "C:\Python37amd64\lib\site-packages\PIL\Image.py", line 2672, in open
    im = _open_core(fp, filename, prefix)
  File "C:\Python37amd64\lib\site-packages\PIL\Image.py", line 2659, in _open_core
    _decompression_bomb_check(im.size)
  File "C:\Python37amd64\lib\site-packages\PIL\Image.py", line 2593, in _decompression_bomb_check
    (pixels, 2 * MAX_IMAGE_PIXELS))
PIL.Image.DecompressionBombError: Image size (295689343 pixels) exceeds limit of 178956970 pixels, could be decompression bomb DOS attack.

Process finished with exit code 1

0 个答案:

没有答案
相关问题