Expand description

Generate a new svg containing the identicon, given a size, a width and a hexadecimal string.

This crate is a port from identicons, a Javascript library written by Bryce Wilson.

While the original library allows for various types of identicon, such as square, polygon and circle, this library allows only the square type. Another difference is that while the original library obtained the icon color from the hash, this crate uses random_color to generate a more bright and visually-pleasing color.

Example

This will generate a new identicon.
The size of the new svg will be between 4x4 and 8x8 (always a square), the width will be 128, the color will be randomly chosen.

Identicons are made from hex hashes and you can provide one yourself. This is not a means of encryption and you should not be using data relative to the user. That’s why by default the hex hash is randomly generated. A function to create random hex hashes is also available.

use identicons_svg::generate;

let svg: String = generate(IdenticonOptions::default())
// svg will be a valid hex string, it could be saved to a file or displayed on a web page

Optional features

  • show-icon - Function show_icon(icon: &str) to save the svg in a temporary file and open it in a tab of the default browser.

Structs

Is the type for the background field of IdenticonOptions. Implements Default: if not otherwise specified the identicon will have a background of color rgb(240, 240, 240) and will not have rounded angles.
Is the argument for the generate function. It implements Default, for an opinionated but quick identicon.

Functions

Generate the new identicon.
Creates a hex string from a random string that can be used for generating an identicon.