Skip to content

Instantly share code, notes, and snippets.

@sprobejames
Created September 2, 2024 23:55
Show Gist options
  • Select an option

  • Save sprobejames/21ea5974c3a6e2ed05f9dd705b9f7027 to your computer and use it in GitHub Desktop.

Select an option

Save sprobejames/21ea5974c3a6e2ed05f9dd705b9f7027 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const { Readable } = require('stream');
const sharp = require('sharp');
const svgToPng = (svgString) => {
return new Promise((resolve, reject) => {
const svgStream = new Readable();
svgStream.push(svgString);
svgStream.push(null);
svgStream.pipe(sharp()
.png()
.toBuffer((err, buffer) => {
if (err) {
reject(err);
}
resolve(buffer);
})
);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment