[][src]Crate initials

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


  • Extern initials crate on your project.
extern crate initials;
  • Draw the avatar by using initials::AvatarBuilder
use initials::AvatarBuilder;
let image = AvatarBuilder::new("Anakin Skywalker")

This will import dynamic RGBA image.

  • If you wish to save the image:
use initials::AvatarBuilder;

let image = AvatarBuilder::new("Anakin Skywalker")


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


initials allows to fully customize the attributes of the image.

Default Attributes
  • font: Hirgino Sans
  • font_scale: 150.0
  • length: 2
  • width: 300
  • height: 300
  • contrast_ratio: 4.5
  • font_color: randomly generated
  • background_color: randomly generated
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

use initials::{AvatarBuilder, AvatarResult};

fn avatar() -> AvatarResult {
    AvatarBuilder::new("Anaking Skywalker")

fn main() {
    let avatar = avatar().unwrap();
    let image = avatar.draw();
  • This will export an initials avatar A with black font and white background.


  • By default, background color and font color will be generated by considering the contrast ratio.
use initials::{AvatarBuilder, AvatarResult};
fn avatar_with_random_font() -> AvatarResult {
    AvatarBuilder::new("Lucky Seven")

fn avatar_with_random_background() -> AvatarResult {
    AvatarBuilder::new("Lucky Seven")

fn main() {
    let img1 = avatar_with_random_background().unwrap().draw();
    let img2 = avatar_with_random_font().unwrap().draw();
  • Means that you may fully customize the colors or unsetted colors will be automatically generated by providing clear and readable avatars according to the contrast ratio.


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



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


Contrast module helps to calculate constrast ratio of two RGB color.


Error module includes the custom error types.


Hex module helps to convert Color Hex Code to RGB.