Files
2026-11-05 01:04:53 +08:00

21 lines
895 B
JavaScript

#!/usr/bin/env node
// Rasterize SVG only; requires sharp in Node's module search path.
const fs = require('node:fs');
const path = require('node:path');
async function main() {
const [input, output, rawWidth = '1920'] = process.argv.slice(2);
const width = Number(rawWidth);
if (!input || !output || !Number.isInteger(width) || width < 1 || width > 16384) {
throw new Error('Usage: node render_svg.cjs input.svg output.png [width: 1..16384]');
}
if (path.resolve(input) === path.resolve(output)) throw new Error('Input and output paths must differ');
const sharp = require('sharp');
const source = fs.readFileSync(input);
fs.mkdirSync(path.dirname(output), {recursive: true});
await sharp(source, {density: 216}).resize({width}).png().toFile(output);
console.log(path.resolve(output));
}
main().catch(error => { console.error(error.message); process.exitCode = 1; });