Created
June 30, 2021 17:28
-
-
Save arn4v/3000059a725596ec6730e16c4f419bb5 to your computer and use it in GitHub Desktop.
Programmatically generate svg avatars
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 { renderToStaticMarkup } = require("react-dom/server.node"); | |
const { createElement } = require("react"); | |
const { default: Jazzicon, jsNumberForAddress } = require("react-jazzicon"); | |
const { JSDOM } = require("jsdom"); | |
const el = createElement(Jazzicon, { | |
diameter: 100, | |
seed: Math.round(Math.random() * 10000000), | |
}); | |
const html = renderToStaticMarkup(el); | |
const svg = new JSDOM(html).window.document.querySelectorAll("div.paper")[0] | |
.innerHTML; | |
console.log(svg); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment