Skip to content

Instantly share code, notes, and snippets.

@chaosong
Created November 21, 2014 11:07
Show Gist options
  • Save chaosong/085661525774eb787ec2 to your computer and use it in GitHub Desktop.
Save chaosong/085661525774eb787ec2 to your computer and use it in GitHub Desktop.
ipython notebook 显示 pil 图像对象
from PIL import Image
import requests
from IPython.display import Image as DisplayImage
import io
def get_im_by_url(url):
r = requests.get(url)
return Image.open(io.BytesIO(r.content))
def display(im):
output = io.BytesIO()
im.save(output, format='JPEG')
return DisplayImage(data=output.getvalue())
url = 'http://userimg.qunar.com/imgs/201405/17/JhS1_t5BrR7WZerTJnormal.jpg'
im = get_im_by_url(url)
display(im)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment