Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable ppi setting on png cli export #8854

Merged
merged 1 commit into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bin/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ To load data, you may need to set a base directory:
if (type === 'vega') {
args.boolean('p').alias('p', 'pretty').describe('p', 'Output human readable/pretty spec.');
}
else if (type === 'png') {
args.number('ppi').describe('ppi', 'Resolution in ppi.');
}

return args.help().version().argv;
};
5 changes: 4 additions & 1 deletion bin/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ module.exports = (type, callback, opt) => {
// set output image scale factor
const scale = arg.scale || undefined;

// Allows for other ppi settings than 72 for png files
const ppi = arg.ppi || 72;

// use a seeded random number generator, if specified
if (typeof arg.seed !== 'undefined') {
if (Number.isNaN(arg.seed)) throw 'Illegal seed value: must be a valid number.';
Expand All @@ -55,7 +58,7 @@ module.exports = (type, callback, opt) => {
renderer: 'none' // no primary renderer needed
}).finalize(); // clear any timers, etc

return (type === 'svg' ? view.toSVG(scale) : view.toCanvas(scale, opt)).then(_ => callback(_, arg));
return (type === 'svg' ? view.toSVG(scale) : view.toCanvas(scale * ppi / 72, opt)).then(_ => callback(_, arg));
}

// read input from file or stdin
Expand Down
2 changes: 1 addition & 1 deletion bin/vl2png
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ const render = require('./render');
render('png', function(canvas, arg) {
const file = arg._[1] || null;
const out = file ? createWriteStream(file) : process.stdout;
const stream = canvas.createPNGStream();
const stream = canvas.createPNGStream({ resolution: arg.ppi || undefined });
stream.on('data', chunk => { out.write(chunk); });
});