- Adjusted YAML and JSON files for consistent formatting, including healthcheck commands and package exports. - Enhanced readability in various TypeScript files by standardizing string quotes and improving line breaks. - Updated documentation across multiple files to improve clarity and consistency, including address system and logging levels. - Removed unnecessary package-lock.json from shared package directory to streamline dependencies.
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Simple SVG -> PNG converter using sharp.
|
|
* Usage: node svg2png.mjs <input.svg> <output.png> <width> <height>
|
|
*/
|
|
import fs from "node:fs/promises";
|
|
import path from "node:path";
|
|
import sharp from "sharp";
|
|
|
|
async function main() {
|
|
const [, , inPath, outPath, wArg, hArg] = process.argv;
|
|
if (!inPath || !outPath || !wArg || !hArg) {
|
|
console.error("Usage: node svg2png.mjs <input.svg> <output.png> <width> <height>");
|
|
process.exit(1);
|
|
}
|
|
const width = Number(wArg);
|
|
const height = Number(hArg);
|
|
if (!width || !height) {
|
|
console.error("Width and height must be numbers");
|
|
process.exit(1);
|
|
}
|
|
|
|
const absIn = path.resolve(inPath);
|
|
const absOut = path.resolve(outPath);
|
|
const svg = await fs.readFile(absIn);
|
|
|
|
// Render with background white to avoid transparency issues in slides
|
|
const png = await sharp(svg, { density: 300 })
|
|
.resize(width, height, { fit: "contain", background: { r: 255, g: 255, b: 255, alpha: 1 } })
|
|
.png({ compressionLevel: 9 })
|
|
.toBuffer();
|
|
|
|
await fs.mkdir(path.dirname(absOut), { recursive: true });
|
|
await fs.writeFile(absOut, png);
|
|
console.log(`Wrote ${absOut} (${width}x${height})`);
|
|
}
|
|
|
|
main().catch(err => {
|
|
console.error("svg2png failed:", err?.message || err);
|
|
process.exit(1);
|
|
});
|