使用requests.get(image_url)

时间:2017-09-26 14:24:16

标签: python matplotlib python-requests

import matplotlib.pyplot as plt
import requests
r = requests.get('https://checkimage.etest.net.cn/65DE0E55A627E56EAA0FA6F8198D2A43.jpg')

如何使用r.text直接显示图像以及它是什么类型的编码?

1 个答案:

答案 0 :(得分:0)

正如request documentation所述:

from PIL import Image
from io import BytesIO

i = Image.open(BytesIO(r.content))

所以在你的情况下:

import matplotlib.pyplot as plt
import requests
from PIL import Image
from io import BytesIO

r = requests.get('https://checkimage.etest.net.cn/65DE0E55A627E56EAA0FA6F8198D2A43.jpg')

im = Image.open(BytesIO(r.content))

plt.imshow(im)
plt.show()