我想标识一个图像的类型来判断它是否是webp
格式,但我不能仅仅使用file
命令,因为图像是以二进制形式存储在内存中的,它是从internet下载的。到目前为止,我在PIL
库或imghdr
库中找不到任何方法来执行此操作
以下是我不想做的事情:
from PIL import Image
import imghdr
image_type = imghdr.what("test.webp")
if not image_type:
print "err"
else:
print image_type
# if the image is **webp** then I will convert it to
# "jpeg", else I won't bother to do the converting job
# because rerendering a image with JPG will cause information loss.
im = Image.open("test.webp").convert("RGB")
im.save("test.jpg","jpeg")
当这个"test.webp"
实际上是一个webp
图像,var image_type
是{webp
类型,那么有没有什么方法可以让我用python确定它是一个webp
图像?在
作为记录,我使用的是python2.7
imghdr
模块还不支持webp图像检测;它将是added to Python 3.5。在在旧版Python上添加它非常简单:
相关问题 更多 >
编程相关推荐