问题
import urllib.request
import Image
urllib.request.urlretrieve("https://www.spriters-resource.com/download/50365/", "mario_image.PNG")
img = Image.open("mario_image.PNG")
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
回答1:
import requests
from PIL import Image
r = requests.get(URL, stream=True)
img = Image.open(r.raw)
来源:https://stackoverflow.com/questions/41050871/how-can-i-retrieve-an-image-from-a-url-and-convert-it-to-a-pil-object