a captcha library for rust
|
|
--- | --- | ---
|
|
```rust use captcha_a::{CaptchaBuilder, Font};
fn main() { let fonts = vec![ Font::tryfrombytes(includebytes!("../fonts/captcha0.ttf")).unwrap(), Font::tryfrombytes(includebytes!("../fonts/captcha1.ttf")).unwrap(), Font::tryfrombytes(includebytes!("../fonts/captcha2.ttf")).unwrap(), Font::tryfrombytes(includebytes!("../fonts/captcha3.ttf")).unwrap(), Font::tryfrombytes(includebytes!("../fonts/captcha4.ttf")).unwrap(), Font::tryfrombytes(includebytes!("../fonts/captcha5.ttf")).unwrap(), ]; let builder = CaptchaBuilder { //custom attribute width: 120, height: 40, length: 4, fonts: &fonts, //default attribute ..Default::default() }; for i in 0..6 { let savepath = format!("image{}.png", i); //each save build and save a new image let phrase = builder.save(&savepath).unwrap(); println!("[{}]phrase={}", i, phrase); } let captcha = builder.build().unwrap(); //require base64 feature let base64url = captcha.base64url(); println!("base64: phrase={}\n{}", captcha.phrase, base64url); } ```