Added basic command-line flags for width and output file name
parent
54adcacdb1
commit
224e1180d1
13
poptimal.js
13
poptimal.js
|
@ -2,6 +2,8 @@ import { Resvg } from "@resvg/resvg-js";
|
|||
import { promises } from "fs";
|
||||
import { JSDOM } from "jsdom";
|
||||
import * as d3 from "d3";
|
||||
import yargs from "yargs/yargs";
|
||||
import { hideBin } from "yargs/helpers";
|
||||
|
||||
import random from "random";
|
||||
|
||||
|
@ -86,19 +88,24 @@ function poptimal_svg() {
|
|||
}
|
||||
|
||||
async function main() {
|
||||
const svg = poptimal_svg();
|
||||
const argv = yargs(hideBin(process.argv))
|
||||
.usage("Usage: -w WIDTH -o OUTPUT_PNG")
|
||||
.default('w', 1200)
|
||||
.default('o', 'poptimal.png').argv;
|
||||
|
||||
const svg = poptimal_svg(argv.w);
|
||||
const opts = {
|
||||
background: 'rgba(255, 255, 255, 1.0)',
|
||||
fitTo: {
|
||||
mode: 'width',
|
||||
value: 1200,
|
||||
value: argv.w,
|
||||
},
|
||||
};
|
||||
const resvg = new Resvg(svg, opts)
|
||||
const pngData = resvg.render()
|
||||
const pngBuffer = pngData.asPng()
|
||||
|
||||
await promises.writeFile('test.png', pngBuffer);
|
||||
await promises.writeFile(argv.o, pngBuffer);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue