简体   繁体   中英

How to view an image with matplotlib when using requests.get(image_url)

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

How can I use r.text to show the image directly and what kind of encoding it is?

As the request documentation states:

from PIL import Image
from io import BytesIO

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

So in your case:

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM