Skip to content

Instantly share code, notes, and snippets.

@AnshKapoor
Created August 17, 2020 17:42
Show Gist options
  • Save AnshKapoor/1fd85ff663c61eacb89ccd9748cbbfdb to your computer and use it in GitHub Desktop.
Save AnshKapoor/1fd85ff663c61eacb89ccd9748cbbfdb to your computer and use it in GitHub Desktop.
A code snippet to save an image from a url in Python
import requests
from io import BytesIO
from PIL import Image
r = requests.get("https://cutewallpaper.org/21/anything-wallpapers/Anything-Wallpapers-Wallpaper-Cave.png")
image = Image.open(BytesIO(r.content))
path = "./image."+image.format
try:
image.save(path, image.format)
except IOError:
print("Cannot save image")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment