File size: 2,171 Bytes
7399b6f | 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 | """Tile every task's opening frame into one high-resolution overview image.
Each cell keeps its full render resolution -- the point of this sheet is to be able to zoom in on
any single scene, so it is deliberately NOT downscaled to fit a screen.
python scripts/task_overview.py # -> outputs/frames/overview.png
python scripts/task_overview.py --cols 6 --scale 1.0
"""
import argparse
import glob
import os
from PIL import Image, ImageDraw, ImageFont
ap = argparse.ArgumentParser()
ap.add_argument("--frames", default="outputs/frames")
ap.add_argument("--out", default="outputs/frames/overview.png")
ap.add_argument("--cols", type=int, default=6)
ap.add_argument("--scale", type=float, default=1.0, help="per-cell scale; 1.0 keeps full res")
ap.add_argument("--pad", type=int, default=10)
ap.add_argument("--label_h", type=int, default=46)
a = ap.parse_args()
paths = sorted(p for p in glob.glob(os.path.join(a.frames, "*.png"))
if os.path.basename(p) != os.path.basename(a.out))
if not paths:
raise SystemExit(f"no frames in {a.frames} -- run yam_task.py --first-frame first")
first = Image.open(paths[0])
cw, ch = int(first.width*a.scale), int(first.height*a.scale)
cols = min(a.cols, len(paths))
rows = (len(paths)+cols-1)//cols
W = cols*cw+(cols+1)*a.pad
H = rows*(ch+a.label_h)+(rows+1)*a.pad
sheet = Image.new("RGB", (W, H), (17, 17, 20))
draw = ImageDraw.Draw(sheet)
try:
font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
max(16, int(cw*0.045)))
except OSError:
font = ImageFont.load_default()
for i, p in enumerate(paths):
r, c = divmod(i, cols)
x = a.pad+c*(cw+a.pad)
y = a.pad+r*(ch+a.label_h+a.pad)
im = Image.open(p).convert("RGB")
if (im.width, im.height) != (cw, ch):
im = im.resize((cw, ch), Image.LANCZOS)
sheet.paste(im, (x, y))
name = os.path.splitext(os.path.basename(p))[0]
draw.text((x+6, y+ch+8), f"{i+1:2d}. {name}", fill=(245, 226, 120), font=font)
sheet.save(a.out)
print(f"[overview] {a.out} {sheet.width} x {sheet.height} px, "
f"{len(paths)} tasks in {cols} x {rows}")
|