fn download(mut req: Request, res: Response) {
    //first set header content type
    res.headers.set(ContentType::png());
    //next,req thread new an png to me
    //Heavy computing tasks should be performed by threads
    let png= spawn_blocking!(||{
        let mut captcha = Captcha::new();
        captcha
            .add_chars(4)
            .apply_filter(Noise::new(0.1))
            .apply_filter(Wave::new(1.0, 10.0).horizontal())
            // .apply_filter(Wave::new(2.0, 20.0).vertical())
            .view(160, 60)
            .apply_filter(Dots::new(4));
        return captcha.as_png().unwrap_or_default() as Vec<u8>;
    });
    //return data
    res.send(&png.unwrap_or_default()).unwrap();
}
/// Draw a captcha code and display it on the web
Draw a captcha code and display it on the web
Draw a captcha code and display it on the web
fn download(mut req: Request, res: Response) {
    //first set header content type
    res.headers.set(ContentType::png());
    //next,req thread new an png to me
    //Heavy computing tasks should be performed by threads
    let png= spawn_blocking!(||{
        let mut captcha = Captcha::new();
        captcha
            .add_chars(4)
            .apply_filter(Noise::new(0.1))
            .apply_filter(Wave::new(1.0, 10.0).horizontal())
            // .apply_filter(Wave::new(2.0, 20.0).vertical())
            .view(160, 60)
            .apply_filter(Dots::new(4));
        return captcha.as_png().unwrap_or_default() as Vec<u8>;
    });
    //return data
    res.send(&png.unwrap_or_default()).unwrap();
}
fn download ( mut req : Request , res : Response ) { //first set header content type res . headers . set ( ContentType :: png ( ) ) ; //next,req thread new an png to me //Heavy computing tasks should be performed by threads let png = spawn_blocking ! ( { let mut captcha Captcha new ( ) captcha add_chars ( 4 ) apply_filter ( Noise new ( 0.1 ) ) apply_filter ( Wave new ( 1.0 10.0 ) horizontal ( ) ) // .apply_filter(Wave::new(2.0, 20.0).vertical()) view ( 160 60 ) apply_filter ( Dots new ( 4 ) ) return captcha as_png ( ) unwrap_or_default ( ) as Vec u8 } ) ; //return data res . send ( & png . unwrap_or_default ( ) ) . unwrap ( ) ; }
Draw a captcha code and display it on the web
Draw a captcha code and display it on the web
req
Request
res
Response
req
Request
res
Response