gigaslop/tools/cf_cut.py
type-two 3a29e08195 Fix live deploy: runtime asset URLs must be relative under /games/gigaslop/
Vite base covered the bundle but Assets.load/img srcs used absolute
/assets/ paths that 404'd on the arcade subpath — the game rendered
placeholder squares in production. All runtime asset references are
now relative.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-01 21:19:56 +10:00

29 lines
990 B
Python

#!/usr/bin/env python3
"""Take CF-flux JPEGs (name_1.jpg) → MB bg_remove_local → autocrop →
public/assets/gen/<name>_cut.png. Usage: python3 tools/cf_cut.py <indir>"""
import pathlib, sys
sys.path.insert(0, str(pathlib.Path(__file__).parent))
from mb_gen import ROOT, run_batch, upload, beat
from PIL import Image
indir = pathlib.Path(sys.argv[1])
gen = ROOT / "public/assets/gen"
jobs = []
for jpg in sorted(indir.glob("*_1.jpg")):
name = jpg.stem[:-2]
jobs.append((f"{name}_cut", "bg_remove_local", upload(jpg),
{"resolution": 1024, "background": "transparent"}))
beat(f"uploaded {name}")
results = run_batch(jobs, gen)
for label in results:
p = gen / f"{label}.png"
im = Image.open(p).convert("RGBA")
bbox = im.split()[-1].getbbox()
if bbox:
l, t, r, b = bbox
im.crop((max(0, l - 8), max(0, t - 8), min(im.width, r + 8), min(im.height, b + 8))).save(p)
beat(f"done: {len(results)} sprites cut + cropped into {gen}")