pub struct CaptchaBuilder { /* private fields */ }Expand description
A builder struct for creating a [Captcha].
Implementations§
Source§impl CaptchaBuilder
impl CaptchaBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Returns a CaptchaBuilder with default configuration.
Examples found in repository?
3fn main() {
4 {
5 let builder = CaptchaBuilder::new();
6
7 let captcha = builder.generate(b"random seed 0", None);
8 println!("text: {}", captcha.text());
9 println!("base_img: {}", captcha.to_base64(0));
10
11 let captcha = builder.generate(b"random seed 1", None);
12 println!("text: {}", captcha.text());
13 println!("base_img: {}", captcha.to_base64(0));
14 }
15
16 {
17 // same as default
18 let builder = CaptchaBuilder::new()
19 .length(4)
20 .width(140)
21 .height(40)
22 .mode(1)
23 .complexity(5);
24
25 let captcha = builder.generate(b"random seed 0", None);
26 println!("text: {}", captcha.text());
27 println!("base_img: {}", captcha.to_base64(30));
28 }
29}Sourcepub fn length(self, length: u8) -> Self
pub fn length(self, length: u8) -> Self
Set the length of the verification code string, default is 4.
Examples found in repository?
3fn main() {
4 {
5 let builder = CaptchaBuilder::new();
6
7 let captcha = builder.generate(b"random seed 0", None);
8 println!("text: {}", captcha.text());
9 println!("base_img: {}", captcha.to_base64(0));
10
11 let captcha = builder.generate(b"random seed 1", None);
12 println!("text: {}", captcha.text());
13 println!("base_img: {}", captcha.to_base64(0));
14 }
15
16 {
17 // same as default
18 let builder = CaptchaBuilder::new()
19 .length(4)
20 .width(140)
21 .height(40)
22 .mode(1)
23 .complexity(5);
24
25 let captcha = builder.generate(b"random seed 0", None);
26 println!("text: {}", captcha.text());
27 println!("base_img: {}", captcha.to_base64(30));
28 }
29}Sourcepub fn fonts(self, fonts: Font<'static>) -> Self
pub fn fonts(self, fonts: Font<'static>) -> Self
Set the font used to generate the captcha image, default is arial-rounded-bold.ttf.
Sourcepub fn width(self, width: u32) -> Self
pub fn width(self, width: u32) -> Self
Set the width of the verification code image, default is 140.
Examples found in repository?
3fn main() {
4 {
5 let builder = CaptchaBuilder::new();
6
7 let captcha = builder.generate(b"random seed 0", None);
8 println!("text: {}", captcha.text());
9 println!("base_img: {}", captcha.to_base64(0));
10
11 let captcha = builder.generate(b"random seed 1", None);
12 println!("text: {}", captcha.text());
13 println!("base_img: {}", captcha.to_base64(0));
14 }
15
16 {
17 // same as default
18 let builder = CaptchaBuilder::new()
19 .length(4)
20 .width(140)
21 .height(40)
22 .mode(1)
23 .complexity(5);
24
25 let captcha = builder.generate(b"random seed 0", None);
26 println!("text: {}", captcha.text());
27 println!("base_img: {}", captcha.to_base64(30));
28 }
29}Sourcepub fn height(self, height: u32) -> Self
pub fn height(self, height: u32) -> Self
Set the height of the verification code image, default is 40.
Examples found in repository?
3fn main() {
4 {
5 let builder = CaptchaBuilder::new();
6
7 let captcha = builder.generate(b"random seed 0", None);
8 println!("text: {}", captcha.text());
9 println!("base_img: {}", captcha.to_base64(0));
10
11 let captcha = builder.generate(b"random seed 1", None);
12 println!("text: {}", captcha.text());
13 println!("base_img: {}", captcha.to_base64(0));
14 }
15
16 {
17 // same as default
18 let builder = CaptchaBuilder::new()
19 .length(4)
20 .width(140)
21 .height(40)
22 .mode(1)
23 .complexity(5);
24
25 let captcha = builder.generate(b"random seed 0", None);
26 println!("text: {}", captcha.text());
27 println!("base_img: {}", captcha.to_base64(30));
28 }
29}Sourcepub fn mode(self, mode: u8) -> Self
pub fn mode(self, mode: u8) -> Self
Set the color mode of the verification code image, default is 1. 0: dark on light, 1: colorful on light, 2: colorful on dark.
Examples found in repository?
3fn main() {
4 {
5 let builder = CaptchaBuilder::new();
6
7 let captcha = builder.generate(b"random seed 0", None);
8 println!("text: {}", captcha.text());
9 println!("base_img: {}", captcha.to_base64(0));
10
11 let captcha = builder.generate(b"random seed 1", None);
12 println!("text: {}", captcha.text());
13 println!("base_img: {}", captcha.to_base64(0));
14 }
15
16 {
17 // same as default
18 let builder = CaptchaBuilder::new()
19 .length(4)
20 .width(140)
21 .height(40)
22 .mode(1)
23 .complexity(5);
24
25 let captcha = builder.generate(b"random seed 0", None);
26 println!("text: {}", captcha.text());
27 println!("base_img: {}", captcha.to_base64(30));
28 }
29}Sourcepub fn complexity(self, complexity: u32) -> Self
pub fn complexity(self, complexity: u32) -> Self
Set the complexity of the verification code image, default is 5.
Examples found in repository?
3fn main() {
4 {
5 let builder = CaptchaBuilder::new();
6
7 let captcha = builder.generate(b"random seed 0", None);
8 println!("text: {}", captcha.text());
9 println!("base_img: {}", captcha.to_base64(0));
10
11 let captcha = builder.generate(b"random seed 1", None);
12 println!("text: {}", captcha.text());
13 println!("base_img: {}", captcha.to_base64(0));
14 }
15
16 {
17 // same as default
18 let builder = CaptchaBuilder::new()
19 .length(4)
20 .width(140)
21 .height(40)
22 .mode(1)
23 .complexity(5);
24
25 let captcha = builder.generate(b"random seed 0", None);
26 println!("text: {}", captcha.text());
27 println!("base_img: {}", captcha.to_base64(30));
28 }
29}Sourcepub fn generate(&self, seed: &[u8], text: Option<String>) -> Captcha
pub fn generate(&self, seed: &[u8], text: Option<String>) -> Captcha
Generate a [Captcha] with the given random seed and a optional text.
If the text is not provided, a text will be generated from random seed.
The random seed can be used only once. You should use a new seed for each new captcha.
Examples found in repository?
3fn main() {
4 {
5 let builder = CaptchaBuilder::new();
6
7 let captcha = builder.generate(b"random seed 0", None);
8 println!("text: {}", captcha.text());
9 println!("base_img: {}", captcha.to_base64(0));
10
11 let captcha = builder.generate(b"random seed 1", None);
12 println!("text: {}", captcha.text());
13 println!("base_img: {}", captcha.to_base64(0));
14 }
15
16 {
17 // same as default
18 let builder = CaptchaBuilder::new()
19 .length(4)
20 .width(140)
21 .height(40)
22 .mode(1)
23 .complexity(5);
24
25 let captcha = builder.generate(b"random seed 0", None);
26 println!("text: {}", captcha.text());
27 println!("base_img: {}", captcha.to_base64(30));
28 }
29}Trait Implementations§
Auto Trait Implementations§
impl Freeze for CaptchaBuilder
impl RefUnwindSafe for CaptchaBuilder
impl Send for CaptchaBuilder
impl Sync for CaptchaBuilder
impl Unpin for CaptchaBuilder
impl UnwindSafe for CaptchaBuilder
Blanket Implementations§
Source§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
Source§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
Source§impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
Source§type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
Source§fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
Source§impl<T> ConvUtil for T
impl<T> ConvUtil for T
Source§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
Source§fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.