Generator script for images
etherinsight opened this issue · comments
etherinsight commented
import os
import json
import asyncio
ASSET_DIR = f"{os.getcwd()}/assets"
with open(f"{ASSET_DIR}/developers.json") as f:
developers = json.load(f)
# output folder mode
mode = 0o777
# Path
path = os.getcwd() + "/final-images"
try:
os.mkdir(path, mode)
except:
pass
# for multiprocessing/ async processing https://stackoverflow.com/a/59385935
def background(f):
def wrapped(*args, **kwargs):
return asyncio.get_event_loop().run_in_executor(None, f, *args, **kwargs)
return wrapped
@background
def generate(i):
dev=developers[i-1]
print(dev)
# remove space and convert location to lowercase
background = str.lower(dev["background"])
background = background.replace(" ", "")
clothing = str.lower(dev["clothing"])
clothing = clothing.replace(" ", "")
industry = str.lower(dev["industry"])
industry = industry.replace(" ", "")
language = str.lower(dev["language"])
language = language.replace(" ", "")
flag = str.lower(dev["location"])
flag = flag.replace(" ", "")
mind = str.lower(dev["mind"])
mind = mind.replace(" ", "")
o_system = str.lower(dev["os"])
o_system = o_system.replace(" ", "")
o_system = o_system.replace("/", "")
o_system = o_system.replace(".", "")
text_editor = str.lower(dev["textEditor"])
text_editor = text_editor.replace(" ", "")
text_editor = text_editor.replace("&", "and")
text_editor = text_editor.replace("++", "")
vibe = str.lower(dev["vibe"])
vibe = vibe.replace(" ", "")
background = Image.open(f"{ASSET_DIR}/traits/background/{background}.png")
background_size = background.size
flag = Image.open(f"{ASSET_DIR}/traits/location/{flag}.png")
flag = flag.resize(background_size)
industry = Image.open(f"{ASSET_DIR}/traits/industry/{industry}.png")
industry = industry.resize(background_size)
language = Image.open(f"{ASSET_DIR}/traits/language/{language}.png")
language = language.resize(background_size)
mind = Image.open(f"{ASSET_DIR}/traits/mind/{mind}.png")
mind = mind.resize(background_size)
o_system = Image.open(f"{ASSET_DIR}/traits/os/{o_system}.png")
o_system = o_system.resize(background_size)
text_editor = Image.open(f"{ASSET_DIR}/traits/texteditor/{text_editor}.png")
text_editor = text_editor.resize(background_size)
vibe = Image.open(f"{ASSET_DIR}/traits/vibe/{vibe}.png")
vibe = vibe.resize(background_size)
clothing = Image.open(f"{ASSET_DIR}/traits/clothing/{clothing}.png")
clothing = clothing.resize(background_size)
# computer = Image.open(f'{ASSET_DIR}/traits/computer/computer.png')
background.paste(industry, (0, 0), industry)
background.paste(flag, (0, 0), flag)
background.paste(mind, (0, 0), mind)
background.paste(o_system, (0, 0), o_system)
background.paste(text_editor, (0, 0), text_editor)
background.paste(vibe, (0, 0), vibe)
background.paste(language, (0, 0), language)
background.paste(clothing, (0, 0), clothing)
# Setting the points for cropped image
left = 295
top = 555
right = 3330
# this will give a 3035*3035 image
bottom_without_cropped_pixels=background_size[1]-1144
im1 = background.crop((left, top, right, bottom_without_cropped_pixels))
# background.paste(computer, (0,0), computer)
# resized_img = background.resize((878, 1136), resample=Image.NEAREST)
im1.save(f'final-images/dev_{dev["id"]}.png', "PNG")
for dev in developers:
generate(int(dev["id"]))