Node發送圖片驗證碼

 

/*
 * 發送圖片驗證碼
 * GET /api/login/sendPictureCode
 * */
router.get('/sendPictureCode',function (req,res,next) {
    let captcha = ccap({
        width:256,//set width,default is 256
        height:60,//set height,default is 60
        offset:40,//set text spacing,default is 40
        quality:100,//set pic quality,default is 50
        // generate:function(){//Custom the function to generate captcha text
        //     //generate captcha text here
        //     return text;//return the captcha text
        //
        // }
    })

    //ary[0] is captcha's text,ary[1] is captcha picture buffer.
    let ary = captcha.get()

    let text = ary[0]
    let buffer = ary[1]
    res.send({
        imgText:text,
        imgSrc:`data:image/png;base64,`+buffer.toString('base64')
    })
})
相關文章
相關標籤/搜索