-
Notifications
You must be signed in to change notification settings - Fork 1
/
stack_layers.py
36 lines (25 loc) · 1.08 KB
/
stack_layers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import random
from PIL import Image
from config import FOLDERS, HEIGHT, N_SAMPLES, SEED, WIDTH
if __name__ == "__main__":
random.seed(SEED)
if "output" not in os.listdir():
os.mkdir("output")
for sample in range(N_SAMPLES):
subfolder = os.listdir(f"layers/{FOLDERS[0]}")
if ".DS_Store" in subfolder:
subfolder.remove(".DS_Store")
img_name = random.choice(subfolder)
base_layer = Image.open(
f"layers/{FOLDERS[0]}/{img_name}").convert("RGBA").resize((WIDTH, HEIGHT), Image.ANTIALIAS)
for f in FOLDERS[1:]:
subfolder = os.listdir(f"layers/{f}")
if ".DS_Store" in subfolder:
subfolder.remove(".DS_Store")
img_name = random.choice(subfolder)
next_layer = Image.open(
f"layers/{f}/{img_name}").convert("RGBA").resize((WIDTH, HEIGHT), Image.ANTIALIAS)
base_layer.paste(next_layer, (0, 0), next_layer)
print(f"* Saving {sample+1}/{N_SAMPLES}")
base_layer.save(f"output/sample_{sample+1}.png", "PNG")