Renders an indenticon and return a Buffer containing a PNG data stream.
jdenticon.toPng(hash|value, size[, padding])
The following example shows how to use
toPng to generate an identicon and save it to a file using Node.js.
var jdenticon = require("jdenticon"), fs = require("fs"), png = jdenticon.toPng("icon value", 200); fs.writeFileSync("./testicon.png", png);
hash|value is considered a hash string if the string is hexadecimal and contains at least 11 characters. It is otherwise considered a value that will be hashed using SHA1.
size defines the width and height, icons are always square, of the icon in pixels, including its padding.
padding specifies the padding surrounding the icon in percents in the range 0.0 to 0.5. Default is 0.08.
To generate PNG icons Jdenticon uses an internal PNG renderer. The renderer depends on several Node.js components that are not available in browsers. The most critical component that is only available on Node.js is a DEFLATE compressor.
There are polyfills available for browser support, but it's hard to justify adding the extra payload required for those polyfills when it is possible, and probably also faster, to just use the
<svg> based renderers. The browser support for
<svg> is also very good these days.