标签:code ring 内存 http blog string python lan import
1. 使用requests(推荐)
from PIL import Image import requests Image.open(requests.get(url, stream=True).raw)
2. 使用StringIO
from PIL import Image from StringIO import StringIO import requests r = requests.get("http://a/b/c") im = Image.open(StringIO(r.content)) im.size
# =======================
from PIL import Image
import urllib2 as urllib
from StringIO import StringIO
fd = urllib.urlopen("http://a/b/c")
im = Image.open(StringIO(fd.read()))
im.size
3. 使用io.BytesIO
from PIL import Image import urllib2 as urllib import io fd = urllib.urlopen("http://a/b/c") image_file = io.BytesIO(fd.read()) im = Image.open(image_file)
标签:code ring 内存 http blog string python lan import
原文地址:http://www.cnblogs.com/jkmiao/p/6295732.html