svg2png-puppeteer

1.0.0 • Public • Published

SVG2PNG Converter Using Puppeteer

You have a SVG file and you need to convert it to PNG. Try with svg2png.

const stringSvg = '<svg viewBox="0 0 100 100"> <circle cx="50" cy="50" r="50" fill="green"> </svg>';
const destinyPath = './';
const fileName = 'mySvg';
await download.main({ stringSvg, destinyPath, fileName });

In the above example, the png file will be genereted in the destinyPath with the fileName 'mySvg'. By default width 1000 will be and height 560.

But you can also specify the size of your image

const stringSvg = '<svg viewBox="0 0 100 100"> <circle cx="50" cy="50" r="50" fill="green"> </svg>';
const destinyPath = './';
const fileName = 'mySvg';
const size = { widht: 100, height: 50 };
await download.main({ stringSvg, destinyPath, fileName, size });

How the conversion is done

svg2png is built on Puppeteer technology to render the SVGs. It just take a screenshot of the content and transforms to png.

Node.js requirements

svg2png uses the latest in ES2015 features, and as such requires a recent version of Node.js. Only the 8.x series onward is supported.

Readme

Keywords

none

Package Sidebar

Install

npm i svg2png-puppeteer

Weekly Downloads

1

Version

1.0.0

License

ISC

Unpacked Size

1.59 MB

Total Files

38

Last publish

Collaborators

  • rubenlupi