这段代码通过urllib2打开远程图片,通过cStringIO读取文件内容,不用保存到磁盘即可读取图片文件的信息
代码语言:javascript复制#!/usr/bin/env python
encoding=utf-8
import cStringIO, urllib2, Image
url = 'https://img.yuanmabao.com/zijie/pic/2021/11/01/oqo0dwb40ra.png'
file = urllib2.urlopen(url)
tmpIm = cStringIO.StringIO(file.read())
im = Image.open(tmpIm)
print im.format, im.size, im.mode</pre>