enthought / chaco

Chaco is a Python package for building interactive and custom 2-D plots.
http://docs.enthought.com/chaco/
Other
292 stars 99 forks source link

display big image file #833

Closed fred4ets closed 2 years ago

fred4ets commented 2 years ago

Hello all,

I would like to display pics from JWST.

But files are quite big (180 MB for Stephan Quintet for instance), so when I use Plot's img_plot(), I get the following error message:

File "/usr/local/lib/python3.9/dist-packages/chaco-5.1.0.dev235-py3.9-linux-x86_64.egg/chaco/image_data.py", line 101, in fromfile
    img = Image(filename)
  File "/usr/local/lib/python3.9/dist-packages/kiva/agg/agg.py", line 1471, in __init__
    pil_img = PilImage.open(file)
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2944, in open
    im = _open_core(fp, filename, prefix, formats)
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2931, in _open_core
    _decompression_bomb_check(im.size)
  File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2841, in _decompression_bomb_check
    raise DecompressionBombError(
PIL.Image.DecompressionBombError: Image size (189811490 pixels) exceeds limit of 178956970 pixels, could be decompression bomb DOS attack.

So I glanced at Google, and I got the following workaround:

Set PIL's MAX_IMAGE_PIXELS to None

OK.

PIL is called in kiva/agg/agg.py line 1468:

from PIL import Image as PilImage

So when I add line:

PilImage.MAX_IMAGE_PIXELS = None

it works fine, there is no more error message.

So my question is: how can I use this trick without modifying Agg source file?

Thanks in advance.

Regards

corranwebster commented 2 years ago

This looks like it is not an Kiva/Agg-specific thing, but a PIL/Pillow global setting. So you should be able to instead do something like:

from PIL import Image

Image.MAX_IMAGE_PIXELS = None

at the top of your script or in your app's main - basically this can go anywhere in your code before you try to load the image.

fred4ets commented 2 years ago

Stupid me.

Thanks a lot.