See the full installation and usage documentation HERE.
I wanted to convert SVGs into diffrent image formats.
Converting a SVG into an image turns out to not be a simple and straight forward as it may seem. Multiple packages already exist on NPM but they all come with a few caveats (that i don't like).
- Some use
puppeteerwhich requires you to download a browser like chromium (130mb download) - Some do not support
Node(work in browsers only) - Some support
CLIonly. - Some only convert to
png
const Svg2 = require("oslllo-svg2");
Svg2("path/to/svg/example.svg")
.png()
.toFile("path/to/save/example.png")
.then(() => {
console.log("done");
})
.catch((error) => {
throw error;
});const Svg2 = require("oslllo-svg2");
Svg2("path/to/svg/example.svg")
.png()
.toFile("path/to/save/example.png", (err) => {
if (err) {
throw err;
} else {
console.log("done");
}
});