webp
イメージの種類を特定してフォーマットかどうかを判断したいのですがfile
、イメージはインターネットからダウンロードしたバイナリとしてメモリに保存されているため、コマンドを使用することはできません。PIL
これまでのところ、 libまたはimghdr
libでこれを行う方法が見つかりません
これが私がしたくないことです:
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
ある場合None
、ライブラリがタイプをimghdr
認識していないことを示すのはどれですか?Pythonで確実に画像であると判断できる方法はありますか?webp
webp
記録のために、私はpython 2.7を使用しています