avatar_gen/image_downloader.py

18 lines
617 B
Python

def download_image(url, filename):
import requests
response = requests.get(url)
if response.status_code != 200:
print(f"Error downloading image from {url}, reason: {response.status_code}")
return False
try:
with open(filename, 'wb') as file:
file.write(response.content)
except Exception as e:
print(f"Error downloading image from {url}, reason: {e}")
return False
return True
def write_image_base64(b64img, filename):
import base64
with open(filename, 'wb') as file:
file.write(base64.b64decode(b64img))