Skip to content
/ svg2 Public

Convert a SVG to multiple image formats (without puppeteer or a headless browser)

License

Notifications You must be signed in to change notification settings

oslllo/svg2

Folders and files

NameName
Last commit message
Last commit date
Nov 21, 2024
Oct 10, 2021
Nov 21, 2024
Nov 21, 2024
Jan 21, 2022
Jul 18, 2020
Jan 21, 2022
Sep 17, 2020
Jul 18, 2020
Nov 21, 2024
Aug 7, 2020
Jan 12, 2022
Nov 21, 2024
Nov 21, 2024

Repository files navigation

Cover Image

CI/Test npm Coverage Status

๐ŸŽ‰ v1.0.0 Removed Canvas & JSDOM no more slow npm install cycles.

Documentation, Installation, and Usage Instructions

See the full installation and usage documentation HERE.

The Objective

I wanted to convert SVGs into diffrent image formats.

The Problem / Why

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 puppeteer which requires you to download a browser like chromium (130mb download)
  • Some do not support Node (work in browsers only)
  • Some support CLI only.
  • Some only convert to png

Usage Examples

Convert a SVG2 png and save to path (promise)

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;
  });

Convert a SVG2 png and save to path (callback)

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");
    }
  });