如何从URL检索图像并将其转换为PIL对象 [英] How can I retrieve an image from a url and convert it to a PIL object
本文介绍了如何从URL检索图像并将其转换为PIL对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
import urllib.request
import Image
urllib.request.urlretrieve("https://www.spriters-resource.com/download/50365/", "mario_image.PNG")
img = Image.open("mario_image.PNG")
我想知道如何从URL中检索图像并将其立即转换为PIL图像,而不必从文件中加载图像
I'm wondering how can I retrieve an image from a url and immediately convert it to a PIL Image without having to load the image from the file
推荐答案
import requests
from PIL import Image
r = requests.get(URL, stream=True)
img = Image.open(r.raw)
这篇关于如何从URL检索图像并将其转换为PIL对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文