Last active
March 17, 2021 17:01
-
-
Save masiamj/bc624aff7fafdf2e7ae744b46a189b3f to your computer and use it in GitHub Desktop.
SVGs to Images!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require("fs"); | |
const axios = require("axios"); | |
const svg2img = require("svg2img"); | |
const getSVGSource = async (id) => { | |
const { data } = await axios.get( | |
`https://www-league.nhlstatic.com/images/logos/teams-current-primary-light/${id}.svg` | |
); | |
return data; | |
}; | |
const convertSVGStringToImage = (id, svgString) => { | |
return new Promise((resolve) => { | |
svg2img(svgString, (error, buffer) => { | |
fs.writeFileSync(`${id}.png`, buffer); | |
resolve(buffer); | |
}); | |
}); | |
}; | |
getSVGSource(15) | |
.then((svgString) => convertSVGStringToImage(15, svgString)) | |
.then(console.log) | |
.catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment