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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//! `initials` crate helps to generate customizable avatars with the initial characters from the names.
//!
//! # Usage
//!
//! - Draw the avatar by using `initials_revamped::AvatarBuilder`
//! ```
//! use initials_revamped::AvatarBuilder;
//!
//! let image = AvatarBuilder::new("Anakin Skywalker")
//!     .draw();
//!
//! ```
//! This will import dynamic RGBA image.
//!
//! - If you wish to save the image:
//! ```
//! use initials_revamped::AvatarBuilder;
//!
//! let image = AvatarBuilder::new("Anakin Skywalker")
//!     .draw();
//!
//! image.save("avatar.jpg").unwrap();
//! ```
//!
//! Or, you may use the resulting buffer to store the image data in a variable
//! ```
//! use image::ImageOutputFormat;
//! use initials_revamped::AvatarBuilder;
//! use std::io::Cursor;
//!
//! let image = AvatarBuilder::new("Anakin Skywalker")
//!     .draw();
//!
//! let mut raw_bytes: Vec<u8> = Vec::new();
//! image.write_to(&mut Cursor::new(&mut raw_bytes), ImageOutputFormat::Png)?;
//! ```
//!
//! # Customization
//!
//! `initials_revamped` allows to fully customize the attributes of the image.
//!
//! ##### Default Attributes
//!   -  **font:** Roboto Regular
//!   -  **font_scale:** 150.0
//!   -  **length:** 2
//!   -  **width:** 300
//!   -  **height:** 300
//!   -  **contrast_ratio:** 4.5
//!   -  **font_color:** randomly generated
//!   -  **background_color:** randomly generated
//!
//! ##### Manipulation
//!
//! |  method | description |
//! |-----------|-------------|
//! |  with_font(str) | Font file path(.ttf)  |
//! |  with_font_data(Vec&lt;u8&gt;) | Font binary data |
//! |  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_revamped::{AvatarBuilder, AvatarResult};
//!
//! fn avatar() -> AvatarResult {
//! 	let custom_font = include_bytes!("fonts/ComicSans.ttf").to_vec();
//!
//!	    AvatarBuilder::new("Anaking Skywalker")
//!         .with_font_color("#000000")?
//! 		.with_font_data(custom_font)?
//!         .with_background_color("#FAFAFA")?
//!         .with_length(1)
//! }
//!
//! fn main() {
//!     let avatar = avatar().unwrap();
//!     let image = avatar.draw();
//! }
//!
//! ```
//! - This will export an initials avatar `A` with black font, white background and Comic Sans as its font.
//!
//!
//! # Randomization
//!
//! - By default, `background color` and `font color` will be generated by considering the contrast ratio.
//!
//! ```
//! use initials_revamped::{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();
//! }
//!
//! ```
//!
//! - 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.

#[macro_use]
extern crate failure;

extern crate image;
extern crate rand;
extern crate rusttype;

pub mod avatar;
pub mod color;
pub mod error;

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