Created
May 17, 2020 20:05
-
-
Save hemendrarajawat/cd8ea61b8bdc2618dbd21493d9620990 to your computer and use it in GitHub Desktop.
Generate dummy random avatar images for profile
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
# Importing Libaries | |
import requests | |
import os | |
import random | |
no_of_images_to_pull = int(input('How many avatars you need? ')) | |
size = tuple(input('Enter the image size(eg. 400x400): ').split('x')) | |
base_url = 'https://dummyimage.com/' | |
colors = ( | |
('fff', '000'), | |
('000', 'fff'), | |
('cf38cf', 'fff'), | |
) | |
formats = ( | |
'png', | |
'jpg', | |
'gif', | |
) | |
folder_name = 'avatar_images' | |
try: | |
os.mkdir(folder_name) | |
except: | |
pass | |
for i in range(no_of_images_to_pull): | |
img_format = formats[int(random.randint(0, 2))] | |
color = colors[int(random.randint(0, 2))] | |
response = requests.get( | |
f'{base_url}{size[0]}x{size[1]}.{img_format}/{color[0]}/{color[1]}&text=Avatar+{i}' | |
) | |
with open(f'{folder_name}/Avatar{i}.{img_format}', 'wb') as file: | |
file.write(response.content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment