Image Cropping Tool (Python)

I am a photo artist who knows a lot about cropping / resizing an image. Since I am making a film, I have to scan my negatives and crop every frame from a batch scan. My scanner scans four bands of six images each (24 frames / crop per scan).

My friend wrote me a Python script that automatically crop images based on the entered coordinates. The script works well, but it has problems in the file format of the exported images.

When scanning, each frame should display 37 MB TIFF at 240 DPI (when I crop and export to Adobe Lightroom). Instead, Cropper outputs a 13 MB 72 DPI TIFF.

The terminal (I'm on a Mac) warns me about the "decompression bomb" whenever I launch Cropper. My friend was at a dead end and suggested that I ask for a stack overflow.

I have no Python experience. I can provide the code that he wrote and the commands that Terminal gives me.

Thoughts? It would be very grateful and a huge BIG time. THANKS!

ERROR MESSAGE: /Library/Python/2.7/site-packages/PIL/Image.py:2192: DecompressionBombWarning: Image size (208560540 pixels) exceeds limit of 89478485 pixels, could be decompression bomb DOS attack. 
+7
python image tiff python-imaging-library pillow
source share
2 answers

PIL is just trying to protect you. It will not open large images, as it could be an attack vector for an attacker to give you a large image that will expand to use all of the memory.

Since you are not a malicious user and are not accepting images from anyone else, you can simply disable the restriction:

 from PIL import Image Image.MAX_IMAGE_PIXELS = None 

Setting Image.MAX_IMAGE_PIXELS completely disables validation. You can also set its (high) integer value; the default is int(1024 * 1024 * 1024 / 4 / 3) , about 90 million pixels or about 250 MB of uncompressed data for a 3-channel image.

Note that by default, everything that happens is a warning. You can also turn off the warning:

 import warnings from PIL import Image warnings.simplefilter('ignore', Image.DecompressionBombWarning) 
+11
source share

From Papers with Pillows :

Warning:. To protect against possible DOS attacks caused by decompression bombs (that is, malicious files that are unpacked into a huge amount of data and are designed to crash or crash due to the use of a large amount of memory), Pillow will issue a DecompressionBombWarning if the image exceeds a certain limit. When warning may optionally be converted into the error via warnings.simplefilter('error', Image.DecompressionBombWarning) or completely disabled via warnings.simplefilter('ignore', Image.DecompressionBombWarning) . See. also documentation protokolirova uw to output warning means logging instead of stderr.

+2
source share

All Articles