eth-blockies-rs

A lightweight library in pure Rust to get Ethereum blockies raw data (or png images), which can be used for creating blockies icon images, printing to terminal, etc.

Supports wide range of targets including Rust bin/lib, and WebAssembly (wasm).

Live Demo

Include to a Rust Cargo crate

Usage Examples

let addr = "0xe686c14FF9C11038F2B1c9aD617F2346CFB817dC" .addr_canonicalize();

// get 2D array of (r, g, b) { let blockiesdatargb = ethblockiesdata(&addr); }

// get 2D array of grayscale { fn rgbtograyscale((r, g, b): RgbPixel) -> u8 { (r as f64 * 0.299 + g as f64 * 0.587 + b as f64 * 0.114) as u8 }

let blockies_data_grayscale =
    eth_blockies_data_mapped(&addr, rgb_to_grayscale);

}

// get (color palette, palette index of each pixel) { let (colorpalette, paletteidxbitmap) = ethblockiesindexeddata(&addr); } ```

let addr = "0xe686c14FF9C11038F2B1c9aD617F2346CFB817dC" .addrcanonicalize(); let dimension = (128, 128); let imgpngdata = ethblockiespngdata(addr, dimension);

use std::io::Write; std::fs::File::create("test.png").unwrap().writeall(&imgpng_data); ```

use web_sys::*;

let addr = "0xe686c14FF9C11038F2B1c9aD617F2346CFB817dC";

window() .andthen(|w| w.document()) .andthen(|doc| doc.body().zip(doc.createelement("img").ok())) .andthen(|(body, img)| { // set data uri to img src ethblockiesdatauri(addr) .andthen(|datauri| img.setattribute("src", &data_uri).ok() );

    img.set_attribute(
        "style",
        concat!(
            // no blur on scaling
            "image-rendering: pixelated !important; ",
            "width: 120px; height: 120px;",
        ),
    );

    body.append_child(&img).ok()
});

```

Author

Kim Hwiwon \

License

The MIT License (MIT)