Skip to content

Instantly share code, notes, and snippets.

@trade74
Created November 6, 2024 05:16
Show Gist options
  • Select an option

  • Save trade74/71f1c38c52963cef803e36b854482536 to your computer and use it in GitHub Desktop.

Select an option

Save trade74/71f1c38c52963cef803e36b854482536 to your computer and use it in GitHub Desktop.
const { SVG } = require('@svgdotjs/svg.js');
const fs = require('fs');
fs.readFile('input.svg', 'utf8', (err, data) => {
if (err) throw err;
const draw = SVG(data);
// Set the new viewBox and size to 24x24
draw.viewbox(0, 0, 24, 24);
draw.size(24, 24);
// Adjust each path element
draw.each((i, children) => {
if (i.type === 'path') {
// Here, if you need to adjust the scale of each path manually
const scaleFactorX = 24 / draw.width();
const scaleFactorY = 24 / draw.height();
i.scale(scaleFactorX, scaleFactorY);
}
});
const resizedSVG = draw.svg();
fs.writeFile('output.svg', resizedSVG, (err) => {
if (err) throw err;
console.log('The SVG has been resized to 24x24!');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment