1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
extern crate image; extern crate hsl; pub mod classic; pub mod ethereum; use std::io; pub use image::ImageError; use image::{Rgba, RgbaImage, GenericImage, DynamicImage, ImageFormat}; use hsl::HSL; fn hsl_to_rgba(hsl: HSL) -> Rgba<u8> { let (r, g, b) = hsl.to_rgb(); Rgba::<u8> { data: [r, g, b, 255], } } fn fill_rect(image: &mut RgbaImage, x: u32, y: u32, size: u32, color: Rgba<u8>) { let mut sub_image = image.sub_image(x, y, size, size); for (_, _ , pixel) in sub_image.pixels_mut() { *pixel = color; } } pub fn rgba(r: u8, g: u8, b: u8, a: u8) -> Rgba<u8> { Rgba::<u8> { data: [r, g, b, a], } } pub enum Blockies { Classic(classic::Options), Ethereum(ethereum::Options), } pub fn create_icon<W>(w: &mut W, blockies: Blockies) -> Result<(), ImageError> where W: io::Write { let image = match blockies { Blockies::Classic(options) => classic::Classic::create_icon(options), Blockies::Ethereum(options) => ethereum::Ethereum::create_icon(options), }; let dy_image = DynamicImage::ImageRgba8(image); dy_image.save(w, ImageFormat::PNG) }