taloria/art/tools/vergleich.py

73 lines
2.6 KiB
Python
Raw Normal View History

2026-11-14 20:58:04 +01:00
#!/usr/bin/env python3
"""Vergleichsblatt aus Bildern bauen — beschriftet, auf gleicher Breite.
Für A/B-Entscheidungen (Stil, Palette, Auflösung, Backend): die Kandidaten
sollen auf dem Schirm **gleich groß** sein, sonst vergleicht man Größen statt
Bilder. Jedes Bild wird deshalb auf dieselbe Breite skaliert (nearest), mit
einer Beschriftung in der 5×7-Pixelschrift darüber.
python3 art/tools/vergleich.py out.png \\
"lokal, B-Block=art/final/Pictures/taverne_B_1280x720.png" \\
"fal, gleicher Prompt=art/final/_versuche/fal_taverne_mit_palette_1280x720.png" \\
--width 1280
Beschriftungen werden upper-case gesetzt; der Font kennt kein `%`, `Ä/Ö/Ü`
und keinen Gedankenstrich — bitte `-` statt `—` verwenden.
"""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
from PIL import Image, ImageDraw
sys.path.insert(0, str(Path(__file__).resolve().parent))
from ui import CREAM, INK, alpha, draw_text # noqa: E402
def label(text: str, width: int) -> Image.Image:
"""Beschriftung in 1×-Schrift, danach 2× — liest sich auf jedem Blatt gleich."""
strip = Image.new("RGBA", (max(1, width // 2), 12), alpha(INK))
draw_text(ImageDraw.Draw(strip), 4, 3, text, CREAM)
return strip.resize((width, 24), Image.NEAREST)
def main(argv: list[str] | None = None) -> int:
ap = argparse.ArgumentParser(description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("out", type=Path)
ap.add_argument("tiles", nargs="+", metavar="BESCHRIFTUNG=BILD")
ap.add_argument("--width", type=int, default=1280)
ap.add_argument("--gap", type=int, default=10)
a = ap.parse_args(argv)
tiles = []
for spec in a.tiles:
if "=" not in spec:
raise SystemExit(f" {spec!r}: erwartet BESCHRIFTUNG=BILD")
text, path = spec.rsplit("=", 1)
im = Image.open(path).convert("RGBA")
scale = a.width / im.width
if scale != 1:
im = im.resize((a.width, round(im.height * scale)), Image.NEAREST)
tiles.append((label(text, a.width), im))
height = sum(t.height + b.height for t, b in tiles) + a.gap * (len(tiles) - 1)
canvas = Image.new("RGBA", (a.width, height), alpha(INK))
y = 0
for strip, im in tiles:
canvas.alpha_composite(strip, (0, y))
y += strip.height
canvas.alpha_composite(im, (0, y))
y += im.height + a.gap
a.out.parent.mkdir(parents=True, exist_ok=True)
canvas.save(a.out)
print(f"{a.out} {canvas.width}x{canvas.height} ({len(tiles)} Bilder)")
return 0
if __name__ == "__main__":
sys.exit(main())