eth-blockies-rs

A lightweight library in pure Rust to get raw data of Ethereum-style blocky identicon, which can be used for generating blockies icon images, printing to terminal, etc.
Useful when getting raw RGB data of Ethereum-style blockies, as well as complete png image files.
Supports general Rust bin/lib, and WebAssembly (wasm) target.
Live Demo

- Check for the wasm demo (Ethereum-style Blockies Generator) to generate your custom blockies.
Library
Documentation
- Check for the full library documentation on docs.rs for details.
Prerequisites
- Add a dependency to
Cargo.tomlof a Rust crate
...or without[] = "1.1"compressed_pngdefault crate feature:[] = { = "1.1", = false }
Library Basic Usage
-
Define a blockies type (size) to use
- Make an alias type of
Blockies
use ; // Blockies < size (const), T > type Icon<T> = ;- Cf) For Ethereum address blockies,
EthBlockiesis predefined as follows
// use statement for Ethereum address blockies use ; // type 'EthBlockies<T>' is predefined as 'Blockies<8, T>' - Make an alias type of
-
Select an input seed type
- Check for
SeedInputto get full list of input seed types
// generate blockies from various input type let from_string = data; let from_byte_vec = data;- Cf) For Ethereum address seeds, apply
to_ethaddr_seed()before passing as input seed
// generate Ethereum address blockies from various input type let seed_from_str = "0xe686c14FF9C11038F2B1c9aD617F2346CFB817dC" .to_ethaddr_seed; let from_str = data; let seed_from_bytes = .to_ethaddr_seed; let from_bytes = data; - Check for
-
Select an output data type
- Check for
BlockiesGeneratorto get full list of output data types
// generate blockies in various forms let in_rgb_2d_arr = data; let in_indexed_2d_arr = indexed_data; let in_gray_2d_arr = data_mapped; let in_png_data_vec = png_data; - Check for
Example
-
Generate an Ethereum address blockies (with
to_ethaddr_seed())use ; let seed = "0xe686c14FF9C11038F2B1c9aD617F2346CFB817dC" .to_ethaddr_seed; // required for Ethereum address blockies // 8x8 2D-array of (r, g, b) // uncompressed png data in byte vector -
Generate an html
imgblockies element, on wasm target// addr to blockies data uri scheme, // which can be used directly in img elem 'src' or css 'url()' use *; let addr = "0xe686c14FF9C11038F2B1c9aD617F2346CFB817dC"; window .and_then .and_then .and_then;
Cargo Features
compressed_png(Enabled by default)- This feature enables following functions:
- This feature adds a following external dependency:
deflatecrate
- If png compression is not needed,
disable this feature as follows when adding the crate:
- E.g.
- Shell:
cargo add eth-blockies@1.1 --no-default-features - Cargo.toml:
eth-blockies = { version = "1.1", default-features = false }
- Shell:
- E.g.
Binary
Install
$ cargo install eth-blockies
Binary Usage
usage: eth-blockies <seed> [output-fmt (ansi|image)] [OPTIONS...]
<seed> Seed to generate blockies (e.g. Ethereum wallet address)
[output-fmt] - ansi (Default) Generate ansi sequence of blockies,
usually for printing to terminal
- image Generate png image data of blockies
[OPTIONS...]:
-e --ethseed Interpret seed string as Ethereum address,
and canonicalize seed (to lowercase + set '0x' prefix)
to get Ethereum blockies correctly
-a --ascii (only for 'ansi' mode) Get non-compact, big blockies
with ascii (non-unicode)
-r --raw (only for 'image' mode) Get uncompressed, raw png image
-s --size=<BLOCKIES_SIZE>
Blockies size: # of elems per side (1-32) (Default: '8')
-d --dimension=<WIDTH>x<HEIGHT>
Dimensions of output in the form of '(width)x(height)'
If not given, following is used (Default):
- ('ansi' mode) '(blockies_size)x(blockies_size)'
- ('image' mode) '128x128'
-o --outfile=<FILENAME>
File name to write output
If the parameter is not given, stdout is used (Default)
examples:
- Outputs from following commands are all the same:
$ eth-blockies 0xe686c14ff9c11038f2b1c9ad617f2346cfb817dc
$ eth-blockies e686c14FF9C11038F2B1c9aD617F2346CFB817dC -e
- Outputs from following commands are all the same:
$ eth-blockies "generic_seed_not_ethaddr" --size=15
$ eth-blockies "generic_seed_not_ethaddr" ansi --size=15 --dimension=15x15
$ eth-blockies "generic_seed_not_ethaddr" a -s 15 -d 15x15
- Outputs from following commands are all the same:
$ eth-blockies "generic_seed" image > blockies.png
$ eth-blockies "generic_seed" i -d128x128 -oblockies.png
$ eth-blockies "generic_seed" i -d 128x128 -o blockies.png
Author
Kim Hwiwon <kim.hwiwon@outlook.com>
License
The MIT License (MIT)