Struct ic_captcha::CaptchaBuilder
source · 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?
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
fn main() {
{
let builder = CaptchaBuilder::new();
let captcha = builder.generate(b"random seed 0", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(0));
let captcha = builder.generate(b"random seed 1", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(0));
}
{
// same as default
let builder = CaptchaBuilder::new()
.length(4)
.width(140)
.height(60)
.mode(1)
.complexity(4);
let captcha = builder.generate(b"random seed 0", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(30));
}
}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?
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
fn main() {
{
let builder = CaptchaBuilder::new();
let captcha = builder.generate(b"random seed 0", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(0));
let captcha = builder.generate(b"random seed 1", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(0));
}
{
// same as default
let builder = CaptchaBuilder::new()
.length(4)
.width(140)
.height(60)
.mode(1)
.complexity(4);
let captcha = builder.generate(b"random seed 0", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(30));
}
}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?
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
fn main() {
{
let builder = CaptchaBuilder::new();
let captcha = builder.generate(b"random seed 0", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(0));
let captcha = builder.generate(b"random seed 1", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(0));
}
{
// same as default
let builder = CaptchaBuilder::new()
.length(4)
.width(140)
.height(60)
.mode(1)
.complexity(4);
let captcha = builder.generate(b"random seed 0", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(30));
}
}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?
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
fn main() {
{
let builder = CaptchaBuilder::new();
let captcha = builder.generate(b"random seed 0", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(0));
let captcha = builder.generate(b"random seed 1", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(0));
}
{
// same as default
let builder = CaptchaBuilder::new()
.length(4)
.width(140)
.height(60)
.mode(1)
.complexity(4);
let captcha = builder.generate(b"random seed 0", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(30));
}
}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?
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
fn main() {
{
let builder = CaptchaBuilder::new();
let captcha = builder.generate(b"random seed 0", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(0));
let captcha = builder.generate(b"random seed 1", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(0));
}
{
// same as default
let builder = CaptchaBuilder::new()
.length(4)
.width(140)
.height(60)
.mode(1)
.complexity(4);
let captcha = builder.generate(b"random seed 0", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(30));
}
}sourcepub fn complexity(self, complexity: u32) -> Self
pub fn complexity(self, complexity: u32) -> Self
Set the complexity of the verification code image, default is 4.
Examples found in repository?
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
fn main() {
{
let builder = CaptchaBuilder::new();
let captcha = builder.generate(b"random seed 0", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(0));
let captcha = builder.generate(b"random seed 1", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(0));
}
{
// same as default
let builder = CaptchaBuilder::new()
.length(4)
.width(140)
.height(60)
.mode(1)
.complexity(4);
let captcha = builder.generate(b"random seed 0", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(30));
}
}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?
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
fn main() {
{
let builder = CaptchaBuilder::new();
let captcha = builder.generate(b"random seed 0", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(0));
let captcha = builder.generate(b"random seed 1", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(0));
}
{
// same as default
let builder = CaptchaBuilder::new()
.length(4)
.width(140)
.height(60)
.mode(1)
.complexity(4);
let captcha = builder.generate(b"random seed 0", None);
println!("text: {}", captcha.text());
println!("base_img: {}", captcha.to_base64(30));
}
}Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for CaptchaBuilder
impl Send for CaptchaBuilder
impl Sync for CaptchaBuilder
impl Unpin for CaptchaBuilder
impl UnwindSafe for CaptchaBuilder
Blanket Implementations§
§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
§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>
§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,
§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
§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
§impl<T> ConvUtil for T
impl<T> ConvUtil for T
§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>,
§fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst, Scheme>,
Scheme: ApproxScheme,
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§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).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.