1 unstable release
0.1.0 | Sep 16, 2022 |
---|
#6 in #identicon
13KB
166 lines
identicon-svg
Rust crate to quickly generate identicon avatar svgs.
Generate a new svg containing the identicon, given a size, a width and a hexadecimal string.
This crate is basically 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 xml string, it could be saved to a file or displayed in a web page
Dependencies
~2.2–6.5MB
~110K SLoC