View Source IdenticonSvg (IdenticonSvg v0.7.0)

Main module of IdenticonSvg that contains all functions of the library.

Link to this section Summary

Functions

Generate the SVG code of the identicon for the specified text.

Link to this section Functions

Link to this function

generate(text, size \\ 5, bg_color \\ nil, opacity \\ 1.0)

View Source

Generate the SVG code of the identicon for the specified text.

Without specifying any optional arguments this function generates a 5x5 identicon with a transparent background and colored grid squares with full opacity.

Optionally, specify any combination of the following arguments:

  • size: the number of grid squares of the identicon's side; integer, 4 to 10; 5 by default.
  • bg_color: the color of the background grid squares; string, hex code (e.g., #eee); nil by default.
  • opacity: the opacity of the entire identicon (all grid squares); float, 0.0 to 1.0; 1.0 by default.

Setting bg_color to nil (default value) generates only the foreground (colored) squares, with the default (1.0) or requested opacity.

The color of the grid squares is always equal to the three first bytes of the hash of text, regardless of which hashing function is used automatically.

A different hashing function is used automatically for each identicon size, so that the utilization of bits is maximized for the given size: MD5 for sizes 4 and 5, RIPEMD-160 for 6, and SHA3 for 7 to 10 with 224, 256, 384 and 512 bits, respectively.

examples

Examples

5x5 identicon with transparent background:

generate("banana")

5x5 identicon for "banana", at full opacity, with transparent background

6x6 identicon with transparent background:

generate("pineapple", 6)

6x6 identicon for "pineapple", at full opacity, with transparent background

7x7 identicon with light gray (#d3d3d3) background:

generate("refrigerator", 7, "#d3d3d3")

7x7 identicon for "refrigerator", at full opacity, with light gray background

9x9 identicon with transparent background and 50% opacity:

generate("2023-03-14", 9, nil, 0.5)

9x9 identicon for "2023-03-14", at 50% opacity, with transparent background

10x10 identicon with yellow (#ff0) background and 80% opacity:

generate("banana", 10, "#ff0", 0.8)

10x10 identicon for "banana", at 80% opacity, with yellow background