如何用PIL获取图像格式?

时间:2021-03-21 00:24:09

After loading an image file with PIL.Image, how can I determine whether the image file is a PNG/JPG/BMP/GIF? I understand very little about these file formats, can PIL get the format metadata from the file header? Or does it need to 'analyze' the data within the file?

使用PIL.Image加载图像文件后,如何确定图像文件是否为PNG / JPG / BMP / GIF?我对这些文件格式了解甚少,PIL可以从文件头获取格式元数据吗?还是需要“分析”文件中的数据?

If PIL doesn't provide such an API, is there any python library that does?

如果PIL没有提供这样的API,那么有没有python库呢?

1 个解决方案

#1