SPB Git

Repository Public

features-contact-sheet.py 2.1 KB 42 lines python

1#!/usr/bin/env python32# SP Notes Core3# File: Scripts/features-contact-sheet.py4# Description: Builds contact sheets of the hosted renders of SPNotesFeatures (written by the snapshot tests in5#              /tmp/spnote-next/shots-native): one sheet per variant (light/dark × compact/regular), every screen labelled.6#              Needs Pillow. Usage: Scripts/features-contact-sheet.py [shots-dir]7#8# Author: Simon-Pierre Boucher9# Contact: contact@spboucher.ai10import glob, math, os, sys11from PIL import Image, ImageDraw, ImageFont1213shots = sys.argv[1] if len(sys.argv) > 1 else "/tmp/spnote-next/shots-native"14try:15    font = ImageFont.truetype("/System/Library/Fonts/Helvetica.ttc", 16)16except Exception:17    font = ImageFont.load_default()1819for scheme in ("light", "dark"):20    for size, thumb_w, columns in (("compact", 260, 8), ("regular", 560, 4)):21        files = sorted(f for f in glob.glob(os.path.join(shots, "*-%s-%s.png" % (scheme, size))) if not os.path.basename(f).startswith("_"))22        if not files: continue23        thumbs = []24        for path in files:25            image = Image.open(path).convert("RGB")26            ratio = thumb_w / image.width27            thumbs.append((os.path.basename(path).replace("-%s-%s.png" % (scheme, size), ""), image.resize((thumb_w, int(image.height * ratio)))))28        cell_h = max(t.height for _, t in thumbs) + 3029        rows = math.ceil(len(thumbs) / columns)30        background = (245, 246, 248) if scheme == "light" else (24, 26, 32)31        ink = (20, 24, 34) if scheme == "light" else (232, 235, 239)32        sheet = Image.new("RGB", (columns * (thumb_w + 12) + 12, rows * (cell_h + 12) + 12), background)33        draw = ImageDraw.Draw(sheet)34        for index, (name, thumb) in enumerate(thumbs):35            x = 12 + (index % columns) * (thumb_w + 12)36            y = 12 + (index // columns) * (cell_h + 12)37            draw.text((x, y), name[:48], fill=ink, font=font)38            sheet.paste(thumb, (x, y + 24))39        out = os.path.join(shots, "_contact-%s-%s.jpg" % (scheme, size))40        sheet.save(out, quality=82)41        print(out, len(thumbs), "renders")42
Files main
Menu

Theme