Created
August 17, 2020 17:42
-
-
Save AnshKapoor/1fd85ff663c61eacb89ccd9748cbbfdb to your computer and use it in GitHub Desktop.
A code snippet to save an image from a url in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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