generate_png

Function generate_png 

Source
pub fn generate_png(
    into_id: &[u8],
    size_in_pixels: u16,
) -> Result<Vec<u8>, EncodingError>
Expand description

Polkadot identicon png data in u8 vector format, from &[u8] input slice

Input slice could be of any length, as it gets hashed anyways; typical input is a public key.

Resulting image quality depends on image size, images start looking acceptable for sizes apporimately 100 pix and above.

§Example

Let’s generate a set of identicons of varying size.

use image::load_from_memory;
use plot_icon::generate_png;

let alice: &[u8] = &[212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205, 227, 154, 86, 132, 231, 165, 109, 162, 125];
let size_set = [16, 32, 45, 64, 128, 256, 512];
for size_in_pixels in size_set.into_iter() {
    let content = generate_png(alice, size_in_pixels).unwrap();
    let image = load_from_memory(&content).unwrap();
    assert!(image.width() == size_in_pixels as u32);
    assert!(image.height() == size_in_pixels as u32);
}