去下载:
import urllib2img = urllib2.urlopen("http://example.com/image.jpg").read()验证可以使用PIL
import StringIOfrom PIL import Imagetry: im = Image.open(StringIO.StringIO(img)) im.verify()except Exception, e: # The image is not valid
即使图像数据无效,如果您只想验证这是图像,也
可以使用imghdr
import imghdrimghdr.what('ignore', img)该方法检查标题并确定图像类型。如果无法识别图像,它将返回无。



