9951 explained code solutions for 126 technologies


python-pillowHow to load an image from url


from PIL import Image
import requests
from io import BytesIO

url = 'https://examples.onelinerhub.com/heroine.png'

response = requests.get(url)
img = Image.open(BytesIO(response.content))

im.show()ctrl + c
PIL

import Pillow package modules

url

url to load image from

requests.get

loads data from given url

Image.open

open given image with Pillow

BytesIO

convert given argument to BytesIO object, so it can be used by Pillow

response.content

get content previously loaded from url

.show()

displays resulting image


How to load an image from url, python pillow

Usage example

from PIL import Image
import requests
from io import BytesIO

url = 'https://examples.onelinerhub.com/heroine.png'

response = requests.get(url)
im = Image.open(BytesIO(response.content))

im.show()