Files
parenthese/tools/layout-bench/crop.mjs
T
IliesAllaliandClaude Opus 5 e8e2485dcd Parenthèse
Galaxie familiale : personnes, unions et filiations, photos, vidéos et voix sur chaque personne,
partage par lien avec consultation sans compte et contributions validées par le propriétaire.
Auto-hébergeable avec Docker. Licence PolyForm Noncommercial 1.0.0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-14 15:49:05 +02:00

17 lines
1.1 KiB
JavaScript

// Usage : node crop.mjs <slug> <personId|prénom> [w=2400] [h=1000] [scale=1]
// Recadre le SVG d'un modèle autour d'une personne, à l'échelle 1 (ou scale), pour comparer localement.
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { svgCropToPng } from './png.mjs'
const [slug, who, w = 2400, h = 1000, scale = 1] = process.argv.slice(2)
const nodes = JSON.parse(readFileSync(new URL(`./out/${slug}.json`, import.meta.url), 'utf8'))
const target = nodes.find(n => n.t === 'person' && (String(n.id) === `p-${who}` || String(n.id) === who || n.name === who))
if (!target) { console.error('introuvable', who); process.exit(1) }
const cx = target.x + target.w / 2, cy = target.y + target.h / 2
const x = Math.round(cx - w / 2), y = Math.round(cy - h / 2)
const svgFile = fileURLToPath(new URL(`./out/${slug}.svg`, import.meta.url))
const outFile = fileURLToPath(new URL(`./out/${slug}-crop-${who}.png`, import.meta.url))
svgCropToPng(svgFile, outFile, { x, y, w: +w, h: +h, scale: +scale })
console.log(outFile, `centre ${target.name} gen ${target.g} @ (${Math.round(cx)}, ${Math.round(cy)})`)