from pathlib import Path from PIL import Image import base64,json,io,shutil root=Path(__file__).resolve().parent;out=root.parent;ip=out/'IP资料包' def uri(im,qual): buf=io.BytesIO();im.save(buf,'WEBP',quality=qual,method=4) return 'data:image/webp;base64,'+base64.b64encode(buf.getvalue()).decode() rows=[] labels=['原型步行','炭笔行走','芦舟撑篙','红陶飞马','敦煌白驹','玛雅登阶','持稿奔跑','浮世绘摇橹','点彩单车','波普摩托','粒子滑板'] cues=['对照手臂反摆与前脚抬起的时机。','炭笔轮廓里看两脚的前后交换。','看篙尖从船头移动到船尾,手和腰跟着换向。','找出伸展、收腿和落蹄;看海叔何时低头俯身。','看白马腾空时缰绳与衣带的变化。','把画面停在膝盖抬得最高的一帧。','跑动时手里的草图和肩膀一起摆动。','比较入水与出水两帧的桨叶角度。','看脚踏绕轴时膝盖的收放。','看握把的手与肩部重心怎样随转弯变化。','观察屈膝压低重心与重新站起。'] fps=[12,12,9,16,15,11,16,9,14,10,12] dirs=sorted((ip/'透明动作序列').iterdir());assert len(dirs)==11 for i,p in enumerate(dirs): files=sorted(p.glob('*.png'));assert len(files)==12 im=Image.new('RGBA',(416*4,300*3)) for j,f in enumerate(files):im.paste(Image.open(f).resize((416,300),Image.Resampling.LANCZOS),(j%4*416,j//4*300)) rows.append(dict(key=p.name,title=labels[i],cue=cues[i],fps=fps[i],sheet=uri(im,88))) turn=Image.open(ip/'设定/海叔-全身三视图.png');turn.thumbnail((1450,850)) page=(root/'ip.html').read_text().replace('/*DATA*/',json.dumps(rows,ensure_ascii=False)).replace('/*TURN*/',uri(turn,89)) (out/'海叔IP-动作资料册.html').write_text(page) shutil.copyfile(out.parent/'海叔-卡通角色母版.png',ip/'设定/海叔-透明全身母版.png') (ip/'动作索引.json').write_text(json.dumps(dict(canvas=[720,520],anchor=[360,495],frame_count_per_action=12,actions=[{k:v for k,v in r.items() if k!='sheet'} for r in rows]),ensure_ascii=False,indent=2))