主要是使用cStringIO库的方法,将内容存放到内存,而后用Image.open方法打开这个文件,就能进行图片的操作了。
- #!/usr/bin/env python
- #encoding=utf-8
- import cStringIO, urllib2, Image
- url = 'http://www.sharejs.com/images/logo.png'
- file = urllib2.urlopen(url)
- tmpIm = cStringIO.StringIO(file.read())
- im = Image.open(tmpIm)
- print im.format, im.size, im.mode
来源: http://www.phpxs.com/code/1005166/