sonjasrasselbande/scripts/make-photos.py
torsten 2c7cae11a5 Add static website for Sonjas Rasselbande
- src/: layout, page fragments, CSS design system, vanilla JS, .htaccess,
  service worker, manifest, SVG artwork
- scripts/: python build (no npm), HTML/link checks, image + photo pipeline,
  FTP deploy with size verification
- docs/: analysis of the old Wix site, architecture notes, deployment
  learnings (FollowSymLinks 500, FTPS data channel, Let's Encrypt),
  open items, source material
- site/ is generated (make build) and gitignored
2026-11-29 19:26:25 +01:00

65 lines
2.3 KiB
Python
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""Erzeugt aus den Original-Fotos in src/assets/img/originals/ die Web-Varianten.
Für jedes Bild entstehen AVIF + WebP + JPEG in mehreren Breiten, damit <picture>
auf dem Handy kleine Dateien lädt. Kein Hochskalieren: Breiten größer als das
Original werden übersprungen.
Aufruf: python3 scripts/make-photos.py
"""
from __future__ import annotations
from pathlib import Path
from PIL import Image
IMG = Path(__file__).resolve().parent.parent / "src" / "assets" / "img"
SRC = IMG / "originals"
# Quelldatei, Zielname, gewünschte Breiten
JOBS: list[tuple[str, str, tuple[int, ...]]] = [
("portrait-sonja.png", "portrait-sonja", (308, 460)),
("gruppe-bank.png", "gruppe-bank", (480, 932)),
("bollerwagen.png", "bollerwagen", (235, 387)),
("tagesablauf-uhr.png", "tagesablauf-uhr", (480, 900)),
]
# Zusätzlicher Beschnitt in Pixeln (links, oben, rechts, unten) – z. B. um am Bildrand
# angeschnittene Fremdpersonen zu entfernen.
CROPS: dict[str, tuple[int, int, int, int]] = {
"portrait-sonja.png": (16, 0, 2, 0),
}
def save_variants(image: Image.Image, name: str, width: int) -> None:
height = round(image.height * width / image.width)
resized = image.resize((width, height), Image.LANCZOS)
base = IMG / f"{name}-{width}"
resized.save(base.with_suffix(".avif"), format="AVIF", quality=52, speed=4)
resized.save(base.with_suffix(".webp"), format="WEBP", quality=78, method=6)
# Fallback: JPEG deckt alle Browser ab (Porträt/Fotos – kein Transparenzbedarf)
resized.save(base.with_suffix(".jpg"), format="JPEG", quality=82, optimize=True,
progressive=True)
print(f" ✓ {name}-{width} (avif/webp/jpg, {width}×{height})")
def main() -> None:
for filename, name, widths in JOBS:
path = SRC / filename
if not path.exists():
print(f" ! fehlt: {path.name}")
continue
image = Image.open(path).convert("RGB")
if filename in CROPS:
left, top, right, bottom = CROPS[filename]
image = image.crop((left, top, image.width - right, image.height - bottom))
for width in widths:
if width > image.width:
continue
save_variants(image, name, width)
if __name__ == "__main__":
main()