from __future__ import annotations
from PIL import Image
def main():
with open('any.webp', 'rb') as f:
try:
im = Image.open(f, formats=('WEBP',))
except Exception:
print(Image.ID) # No WEBP in the list
raise
else:
print(im.size)
if __name__ == '__main__':
main()
['BMP', 'DIB', 'GIF', 'TIFF', 'JPEG', 'PPM', 'PNG']
Traceback (most recent call last):
File "pil_debug.py", line 18, in <module>
main()
File "pil_debug.py", line 9, in main
im = Image.open(f, formats=('WEBP',))
File "lib\site-packages\PIL\Image.py", line 2929, in open
im = _open_core(fp, filename, prefix, formats)
File "lib\site-packages\PIL\Image.py", line 2909, in _open_core
factory, accept = OPEN[i]
KeyError: 'WEBP'
In
open(),preinit()only initialize popular formats,_open_core()will raise if the given formats have not been initialized. Theinit()failback become unreachable.Pillow/src/PIL/Image.py
Lines 2901 to 2934 in 2d6e51e
What did you do?
What did you expect to happen?
Output the size
(640, 480)What actually happened?
What are your OS, Python and Pillow versions?