Skip to content

Instantly share code, notes, and snippets.

@arn4v
Created June 30, 2021 17:28
Show Gist options
  • Save arn4v/3000059a725596ec6730e16c4f419bb5 to your computer and use it in GitHub Desktop.
Save arn4v/3000059a725596ec6730e16c4f419bb5 to your computer and use it in GitHub Desktop.
Programmatically generate svg avatars
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