ThreeKingdomsSlingshot/Tools/vfx_capture/tile.py

19 lines
929 B
Python

import sys, os, glob, math
from PIL import Image, ImageDraw, ImageFont
D=sys.argv[1]; ids=sys.argv[2].split(','); cell=int(sys.argv[3]) if len(sys.argv)>3 else 400
try: font=ImageFont.truetype('C:/Windows/Fonts/consola.ttf',14)
except Exception: font=ImageFont.load_default()
for hid in ids:
fs=sorted(glob.glob(os.path.join(D,hid+'_[0-9][0-9]_*.png')))
if not fs: print('no frames',hid); continue
cols=min(4,len(fs)); rows=math.ceil(len(fs)/cols)
sh=Image.new('RGB',(cols*cell,rows*cell),(20,20,24)); dr=ImageDraw.Draw(sh)
for i,f in enumerate(fs):
im=Image.open(f).resize((cell,cell),Image.LANCZOS)
x=(i%cols)*cell; y=(i//cols)*cell
sh.paste(im,(x,y))
tag=os.path.basename(f)[len(hid)+4:-4]
dr.rectangle((x,y,x+70,y+18),fill=(0,0,0)); dr.text((x+3,y+2),tag,fill=(255,255,120),font=font)
sh.save(os.path.join(D,'sheet_'+hid+'.png'))
print('sheet',hid,len(fs))