Files
parenthese/tools/layout-bench/png.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

19 lines
938 B
JavaScript

// SVG → PNG : vue d'ensemble (largeur fixe) + crop (fenêtre du viewBox à l'échelle 1)
import { readFileSync, writeFileSync } from 'node:fs'
import { Resvg } from '@resvg/resvg-js'
export function svgToPng(svgFile, pngFile, { width = 2400 } = {}) {
const svg = readFileSync(svgFile, 'utf8')
const r = new Resvg(svg, { fitTo: { mode: 'width', value: width }, background: '#FDF8EC' })
writeFileSync(pngFile, r.render().asPng())
}
// crop : remplace le viewBox par la fenêtre demandée (coordonnées layout)
export function svgCropToPng(svgFile, pngFile, { x, y, w, h, scale = 1 }) {
const svg = readFileSync(svgFile, 'utf8')
.replace(/viewBox="[^"]+"/, `viewBox="${x} ${y} ${w} ${h}"`)
.replace(/ width="[^"]+" height="[^"]+"/, ` width="${w}" height="${h}"`)
const r = new Resvg(svg, { fitTo: { mode: 'width', value: Math.round(w * scale) }, background: '#FDF8EC' })
writeFileSync(pngFile, r.render().asPng())
}