Added Image.WARN_POSSIBLE_FORMATS by radarhere · Pull Request #8063 · python-pillow/Pillow
Resolves #7993. Alternative to #8033
If a user tries to open the image from that issue
from PIL import Image Image.open("bug.png")
they will see
Traceback (most recent call last): File "demo.py", line 2, in <module> Image.open("bug.png") File "PIL/Image.py", line 3380, in open raise UnidentifiedImageError(msg) PIL.UnidentifiedImageError: cannot identify image file 'bug.png'
If the user would like to investigate further, this PR adds "warn_possible_formats". It will show any errors raised during the checking of the formats as warnings.
from PIL import Image Image.WARN_POSSIBLE_FORMATS = True Image.open("bug.png")
giving
PIL/Image.py:3378: UserWarning: PNG opening failed. broken PNG file (bad header checksum in b'pHYs') warnings.warn(message) PIL/Image.py:3378: UserWarning: IM opening failed. Syntax error in IM header: �PNG warnings.warn(message) PIL/Image.py:3378: UserWarning: IMT opening failed. not identified by this driver warnings.warn(message) PIL/Image.py:3378: UserWarning: IPTC opening failed. invalid IPTC/NAA file warnings.warn(message) PIL/Image.py:3378: UserWarning: PCD opening failed. not a PCD file warnings.warn(message) PIL/Image.py:3378: UserWarning: SPIDER opening failed. not a valid Spider file warnings.warn(message) PIL/Image.py:3378: UserWarning: TGA opening failed. not a TGA file warnings.warn(message) Traceback (most recent call last): File "demo.py", line 3, in <module> Image.open("bug.png", warn_possible_formats=True) File "PIL/Image.py", line 3380, in open raise UnidentifiedImageError(msg) PIL.UnidentifiedImageError: cannot identify image file 'bug.png'