pub struct RngCaptcha<T> { /* private fields */ }
Expand description
A CAPTCHA.
Implementations§
Source§impl<T: Rng + RngCore> RngCaptcha<T>
impl<T: Rng + RngCore> RngCaptcha<T>
pub fn from_rng(rng: T) -> RngCaptcha<T>
Sourcepub fn apply_filter<F: Filter>(&mut self, f: F) -> &mut Self
pub fn apply_filter<F: Filter>(&mut self, f: F) -> &mut Self
Applies the filter f
to the CAPTCHA.
This method is used to add noise, grids, etc or to transform the shape of the CAPTCHA.
Sourcepub fn set_font<F: Font + 'static>(&mut self, f: F) -> &mut Self
pub fn set_font<F: Font + 'static>(&mut self, f: F) -> &mut Self
Sets another font that is used for the characters.
Calling this method does not have an effect on the font of the characters which have already been added to the CAPTCHA. The new font is only applied to the characters which are written to the CAPTCHA after this method is called.
If characters have been set via set_chars(), this method will overwrite the setting.
pub fn set_color(&mut self, color: [u8; 3]) -> &mut Self
Sourcepub fn save(&self, p: &Path) -> Result<()>
pub fn save(&self, p: &Path) -> Result<()>
Saves the CAPTCHA to a image file.
The format that is written is determined from the filename’s extension. On error Err
is
returned.
Sourcepub fn set_chars(&mut self, c: &[char]) -> &mut Self
pub fn set_chars(&mut self, c: &[char]) -> &mut Self
Sets the characters that should be used when generating a CAPTCHA.
Important: The characters have to exist for the current font. You can get all characters which are supported by the current font by calling supported_chars().
Sourcepub fn add_text_area(&mut self) -> &mut Self
pub fn add_text_area(&mut self) -> &mut Self
Adds a red box to the CAPTCHA representing the area which contains text.
Sourcepub fn text_area(&self) -> Geometry
pub fn text_area(&self) -> Geometry
Returns the geometry of the area which contains text in the CAPTCHA.
Sourcepub fn extract(&mut self, area: Geometry) -> &mut Self
pub fn extract(&mut self, area: Geometry) -> &mut Self
Crops the CAPTCHA to the given geometry.
Sourcepub fn view(&mut self, w: u32, h: u32) -> &mut Self
pub fn view(&mut self, w: u32, h: u32) -> &mut Self
Crops the CAPTCHA to the given width and height with the text centered withing this box.
Sourcepub fn chars_as_string(&self) -> String
pub fn chars_as_string(&self) -> String
Returns the characters that have been added to this CAPTCHA collected into a string.
Sourcepub fn add_chars(&mut self, n: u32) -> &mut Self
pub fn add_chars(&mut self, n: u32) -> &mut Self
Adds the given number of random characters to the CAPTCHA using the current font.
Sourcepub fn as_wav(&self) -> Vec<Option<Vec<u8>>>
pub fn as_wav(&self) -> Vec<Option<Vec<u8>>>
Returns for each letter in the CAPTCHA an audio in WAV format.
Warning: Currently this feature is rather limited. The same audio data is returned for the same letter, i.e. no noise is added. Someone could solve the CAPTCHA by simply having the audio for each letter and comparing them with the current challenge.
Sourcepub fn as_png(&self) -> Option<Vec<u8>>
pub fn as_png(&self) -> Option<Vec<u8>>
Returns the CAPTCHA as a png image.
Returns None
on error.
pub fn as_base64(&self) -> Option<String>
Sourcepub fn as_tuple(&self) -> Option<(String, Vec<u8>)>
pub fn as_tuple(&self) -> Option<(String, Vec<u8>)>
Returns a tuple which contains the characters that have been added to this CAPTCHA as a string and the image encoded as a PNG.
Returns None
on error.
Sourcepub fn supported_chars(&self) -> Vec<char>
pub fn supported_chars(&self) -> Vec<char>
Returns the supported characters of the current font.
Auto Trait Implementations§
impl<T> Freeze for RngCaptcha<T>where
T: Freeze,
impl<T> !RefUnwindSafe for RngCaptcha<T>
impl<T> !Send for RngCaptcha<T>
impl<T> !Sync for RngCaptcha<T>
impl<T> Unpin for RngCaptcha<T>where
T: Unpin,
impl<T> !UnwindSafe for RngCaptcha<T>
Blanket Implementations§
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more