-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
What did you do?
Used PIL Image, ImageSequence classes in python to load and process a .tif file.
Case (1)
This specific file is titled "MultipleFormats.tif" and is available at:
https://www.leadtools.com/support/forum/posts/t10960-
This TIF file contains JPG2000 compression on its third page. It is here that the code fails
Case(2) Tried other files that were converted using online pdf to tiff converters. Sorry, I do not have these files handy
What did you expect to happen?
Process all the pages of the given TIFF file
What actually happened?
Case (1)
Exception when reading from COMPRESSION list in TiffImagePlugin -> _setup() -> Line 1259. JPEG2000 compression key is 34712, which is not defined in COMPRESSION list causing a "keyerror" 34712
Case (2)
With other test files, I noticed that: TiffImagePlugin -> _setup() is failing in line 1280 with typecasting error, as the get() method below returned "None"
x_size = int(self.tag_v2.get(IMAGEWIDTH))
If a SyntaxError can be raised for this situation instead of optimistically typecasting to int(), it would not break the code and I can handle it in my exception handler in the calling code
What are your OS, Python and Pillow versions?
- OS: Ubuntu
- Python: 3.8
- Pillow: 9.0.0
from PIL import Image, ImageSequence
tiff_file_name = "MultiFormats.tif"
# Read the file
with Image.open(tiff_file_name) as tiff_img:
for i, page in enumerate(ImageSequence.Iterator(tiff_image)):
print (f"Page {i}: Mode: {page.mode}, Size: {page.size}")