Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用 PIL.Image 加载图像文件后,如何确定图像文件是否为 PNG/JPG/BMP/GIF?我对这些文件格式了解甚少,PIL 可以format从文件头中获取元数据吗?还是需要“分析”文件中的数据?
format
如果 PIL 不提供这样的 API,是否有任何 python 库可以提供?
尝试:
img = Image.open(filename) print(img.format) # 'JPEG'
更多信息
https://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.Image.format
https://pillow.readthedocs.io/en/latest/handbook/image-file-formats.html