Created
November 21, 2014 11:07
-
-
Save chaosong/085661525774eb787ec2 to your computer and use it in GitHub Desktop.
ipython notebook 显示 pil 图像对象
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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