[][src]Crate initials

initials crate helps to generate customizable avatars with the initial characters from the names.

Usage

extern crate initials;
use initials::AvatarBuilder;
 
let image = AvatarBuilder::new("Anakin Skywalker")
    .draw();

This will import dynamic RGBA image.

use initials::AvatarBuilder;

let image = AvatarBuilder::new("Anakin Skywalker")
    .draw();

image.save("avatar.jpg").unwrap();

Or, you may manipulate DynamicImage according to your needs after building.(Docs)

Customization

initials allows to fully customize the attributes of the image.

Default Attributes
Manipulation
method description
with_font(str) Font file path(.ttf)
with_font_color(str) Font hex color code
with_font_scale(f32) Uniform scale of the text
with_background_color(str) Background hex color code
with_length(usize) Font length
with_height(u32) Image height
with_width(u32) Image width
with_contrast_ratio(u32) Contrast ratio for the randomly generated colors
with_blur(f32) Applied Gaussian Filter
Example

use initials::{AvatarBuilder, AvatarResult};

fn avatar() -> AvatarResult {
    AvatarBuilder::new("Anaking Skywalker")
        .with_font_color("#000000")?
        .with_background_color("#FAFAFA")?
        .with_length(1)
}

fn main() {
    let avatar = avatar().unwrap();
    let image = avatar.draw();
}

Randomization

use initials::{AvatarBuilder, AvatarResult};
    
fn avatar_with_random_font() -> AvatarResult {
    AvatarBuilder::new("Lucky Seven")
        .with_background_color("#FAFAFA")
}

fn avatar_with_random_background() -> AvatarResult {
    AvatarBuilder::new("Lucky Seven")
        .with_font_color("#000000")
}

fn main() {
    let img1 = avatar_with_random_background().unwrap().draw();
    let img2 = avatar_with_random_font().unwrap().draw();
}

Re-exports

pub use avatar::AvatarBuilder;
pub use avatar::AvatarResult;
pub use error::Error;

Modules

avatar

Avatar module helps to generate avatars according to the initial names.

color

Color module that helps generating and operating on rgb colors

error

Error module includes the custom error types.