Skip to content

Instantly share code, notes, and snippets.

@kgn
Created October 12, 2021 04:32
Show Gist options
  • Save kgn/c318e858557873b20831b2f453c71f9e to your computer and use it in GitHub Desktop.
Save kgn/c318e858557873b20831b2f453c71f9e to your computer and use it in GitHub Desktop.
Convert svg to png
import svg2img from 'svg2img';
module.exports = (req, res) => {
const url = req.query.url;
const width = req.query.width;
const height = req.query.height;
const size = Math.min(width, height);
svg2img(url, {width: size, height: size, preserveAspectRatio: true},
function(error, buffer) {
if (buffer) {
res.send(buffer);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment