时间:2021-07-01 10:21:17 帮助过:34人阅读
content = u'你好 sharejs.com' content = content.encode('utf-8') content = urllib2.quote(content) api_url = 'http://www.sharejs.com/q=%s'%content res = urllib2.urlopen(api_url)
获取远程图片的大小和尺寸
这段代码通过urllib2打开远程图片,通过cStringIO读取文件内容,不用保存到磁盘即可读取图片文件的信息
#!/usr/bin/env python #encoding=utf-8 import cStringIO, urllib2, Image url = 'http://www.01happy.com/wp-content/uploads/2012/09/bg.png' file = urllib2.urlopen(url) tmpIm = cStringIO.StringIO(file.read()) im = Image.open(tmpIm) print im.format, im.size, im.mode