-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombine_spritesheets.py
More file actions
64 lines (48 loc) · 1.7 KB
/
combine_spritesheets.py
File metadata and controls
64 lines (48 loc) · 1.7 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import os
from psd_tools import PSDImage
from PIL import Image
import sys
from bcolors import bc
import glob
import inquirer
from pprint import pprint
from tqdm import tqdm
sys.path.append(os.path.realpath("."))
print(f" Welcome to the sprite sheet combiner! This programs allows to to combine single animations like the ones generated from {bc.B} psd_to_spritesheet.py{bc.E} into a single vertical sprite sheet with multiple animations (PNG format)\n ")
print(f"Make sure to move the sheets you want to combine into the spriteSheets directory ")
pngs = []
output_sheet=None
height=0
maxWidth=0
name="example"
names = []
def createNewSheet():
widths, heights = zip(*(i.size for i in pngs))
height= sum(heights) #horizontal max
maxWidth = max(widths)
output_sheet = Image.new('RGB', (maxWidth, height))
y_offset = 0
for img in tqdm(pngs,colour="green",postfix="psd-to-spritesheet",dynamic_ncols=True, desc="frames to spritesheet "):
output_sheet.paste(img, (0,y_offset))
y_offset += img.size[1]
output_sheet.save(f'./combinedSpritesheets/example.png', )
#Pngs
dir_path = "./spritesheets"
for filepath in glob.glob(f"{dir_path}/*.png"):
#array of name: (regex) path: path, imgWidth
o=Image.open(filepath)
maxWidth = o.size[0] if o.size[0] > maxWidth else print()
height += o.size[1]
pngs.append(o)
names.append(filepath)
# eh =list(map((lambda x: x.name), getAllPNGs()))
print(f"Which of these do you wish to combine? \n [ARROW KEYS + SPACEBAR to select]/n/n")
answers = inquirer.prompt([
inquirer.Checkbox(
"spritesheets",
message="select 2 or more",
choices=names,
default=pngs
),
])
createNewSheet()