from PIL import Image import urllib2 Image.open(urllib2.urlopen(url))
…or using requests:
from PIL import Image import requests Image.open(requests.get(url, stream=True).raw)
As mentioned by mjpieters on the PR requests does not automatically decode
gzip responses, so if you’re downloading images that have been further compressed for whatever reason you must set
decode_content=True on the response object before accessing
response = requests.get(url, stream=True) response.raw.decode_content = True image = Image.open(response.raw)
Get regular FAQs tips & tutorials direct to your Inbox.