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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//! # Adaptemoji
//!
//! Convert your regular Telegram emojis into adaptive monochrome versions
//!
//! ## Installation as CLI
//!
//! ```bash
//! cargo install adaptemoji
//! ```
//!
//! ## How to use
//!
//! ### Regular
//!
//! ```bash
//! adaptemoji -i your-image.png -o output-image.png
//! ```
//!
//! ### Negative
//!
//! ```bash
//! adaptemoji -i your-image.png -o output-image.png -n
//! ```
//!
//! Also Telegram requires your emoji to be 100px x 100px in size. If you want adaptemoji automatically to resize image, add `-r` flag
//!
//! ### Regular resized
//!
//! ```bash
//! adaptemoji -i your-image.png -o output-image.png -r
//! ```
//!
//! ### Negative resized
//!
//! ```bash
//! adaptemoji -i your-image.png -o output-image.png -nr
//! ```
//!
//! ## Using as library
//!
//! ### Installation
//!
//! ```bash
//! cargo add adaptemoji
//! ```
//!
//! ### Examples
//!
//! ```rust
//! use adaptemoji::AdaptiveEmojiConvert;
//! use std::error;
//!
//! fn main() -> Result<(), Box<dyn error::Error>> {
//! let img = image::open("./assets/examples/original.webp")?;
//! let mut resized_img = img
//! .resize(100, 100, image::imageops::FilterType::Triangle)
//! .to_luma_alpha8();
//!
//! resized_img.convert_adaptive(false).save("./target/adaptive.png")?;
//!
//! Ok(())
//! }
//! ```
//!
//! ```rust
//! use adaptemoji::AdaptiveEmojiConvert;
//! use std::error;
//!
//! fn main() -> Result<(), Box<dyn error::Error>> {
//! let img = image::open("./assets/examples/original.webp")?;
//! let mut resized_img = img
//! .resize(100, 100, image::imageops::FilterType::Triangle)
//! .to_luma_alpha8();
//!
//! adaptemoji::convert_adaptive(&mut resized_img, true);
//! resized_img.save("./target/adaptive_negative.png")?;
//!
//! Ok(())
//! }
//! ```
/// Converts the pixels of a GrayAlphaImage to negative if `negative` is true,
/// otherwise, converts them to positive.
///
/// For Telegram's adaptive emojis, it doesn't matter, made to better show
/// what should you use depending on the background.
///
/// # Arguments
///
/// * `img` - A mutable reference to a GrayAlphaImage.
/// * `negative` - A boolean indicating whether to convert to negative or not.
///
/// # Examples
///
/// ```
/// # fn main() -> Result<(), image::ImageError> {
/// let mut img = image::open("./assets/examples/original.webp")?.to_luma_alpha8();
///
/// adaptemoji::convert_adaptive(&mut img, true);
/// # Ok(())
/// # }
/// ```
/// Convert your emoji into adaptive one