Created
November 6, 2024 05:16
-
-
Save trade74/71f1c38c52963cef803e36b854482536 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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