initials_revamped/lib.rs
1//! `initials` crate helps to generate customizable avatars with the initial characters from the names.
2//!
3//! # Usage
4//!
5//! - Draw the avatar by using `initials_revamped::AvatarBuilder`
6//! ```
7//! use initials_revamped::AvatarBuilder;
8//!
9//! let image = AvatarBuilder::new("Anakin Skywalker")
10//! .draw();
11//!
12//! ```
13//! This will import dynamic RGBA image.
14//!
15//! - If you wish to save the image:
16//! ```
17//! use initials_revamped::AvatarBuilder;
18//!
19//! let image = AvatarBuilder::new("Anakin Skywalker")
20//! .draw();
21//!
22//! image.save("avatar.jpg").unwrap();
23//! ```
24//!
25//! Or, you may use the resulting buffer to store the image data in a variable
26//! ```
27//! use image::ImageOutputFormat;
28//! use initials_revamped::AvatarBuilder;
29//! use std::io::Cursor;
30//!
31//! let image = AvatarBuilder::new("Anakin Skywalker")
32//! .draw();
33//!
34//! let mut raw_bytes: Vec<u8> = Vec::new();
35//! image.write_to(&mut Cursor::new(&mut raw_bytes), ImageOutputFormat::Png)?;
36//! ```
37//!
38//! # Customization
39//!
40//! `initials_revamped` allows to fully customize the attributes of the image.
41//!
42//! ##### Default Attributes
43//! - **font:** Roboto Regular
44//! - **font_scale:** 150.0
45//! - **length:** 2
46//! - **width:** 300
47//! - **height:** 300
48//! - **contrast_ratio:** 4.5
49//! - **font_color:** randomly generated
50//! - **background_color:** randomly generated
51//!
52//! ##### Manipulation
53//!
54//! | method | description |
55//! |-----------|-------------|
56//! | with_font(str) | Font file path(.ttf) |
57//! | with_font_data(Vec<u8>) | Font binary data |
58//! | with_font_color(str) | Font hex color code |
59//! | with_font_scale(f32) | Uniform scale of the text |
60//! | with_background_color(str) | Background hex color code |
61//! | with_length(usize) | Font length |
62//! | with_height(u32) | Image height |
63//! | with_width(u32) | Image width |
64//! | with_contrast_ratio(u32) | Contrast ratio for the randomly generated colors |
65//! | with_blur(f32) | Applied Gaussian Filter |
66//!
67//! ##### Example
68//!
69//! ```
70//!
71//! use initials_revamped::{AvatarBuilder, AvatarResult};
72//!
73//! fn avatar() -> AvatarResult {
74//! let custom_font = include_bytes!("fonts/ComicSans.ttf").to_vec();
75//!
76//! AvatarBuilder::new("Anaking Skywalker")
77//! .with_font_color("#000000")?
78//! .with_font_data(custom_font)?
79//! .with_background_color("#FAFAFA")?
80//! .with_length(1)
81//! }
82//!
83//! fn main() {
84//! let avatar = avatar().unwrap();
85//! let image = avatar.draw();
86//! }
87//!
88//! ```
89//! - This will export an initials avatar `A` with black font, white background and Comic Sans as its font.
90//!
91//!
92//! # Randomization
93//!
94//! - By default, `background color` and `font color` will be generated by considering the contrast ratio.
95//!
96//! ```
97//! use initials_revamped::{AvatarBuilder, AvatarResult};
98//!
99//! fn avatar_with_random_font() -> AvatarResult {
100//! AvatarBuilder::new("Lucky Seven")
101//! .with_background_color("#FAFAFA")
102//! }
103//!
104//! fn avatar_with_random_background() -> AvatarResult {
105//! AvatarBuilder::new("Lucky Seven")
106//! .with_font_color("#000000")
107//! }
108//!
109//! fn main() {
110//! let img1 = avatar_with_random_background().unwrap().draw();
111//! let img2 = avatar_with_random_font().unwrap().draw();
112//! }
113//!
114//! ```
115//!
116//! - Means that you may fully customize the colors or unsetted colors will be automatically generated
117//! by providing clear and readable avatars according to the contrast ratio.
118
119#[macro_use]
120extern crate failure;
121
122extern crate image;
123extern crate rand;
124extern crate rusttype;
125
126pub mod avatar;
127pub mod color;
128pub mod error;
129
130pub use avatar::AvatarBuilder;
131pub use avatar::AvatarResult;
132pub use error::Error;