How do I open an image from the internet in PIL?
You might consider using io.BytesIO
for forward compatibility.
The StringIO and cStringIO modules do not exist in Python 3.
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)
Using Python requests
:
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