captcha plugin for egg framework, based on ccap
$ npm i egg-captcha --save
// {app_root}/config/plugin.js
exports.captcha = {
enable: true,
package: 'egg-captcha',
};
// {app_root}/config/config.default.js
exports.captcha = {
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
fontsize: 57 // set font size,default is 57
}
see config/config.default.js for more detail.
// {app_root}/controller/user.js
async captcha() {
const {ctx, service} = this
const {captcha, txt} = await service.user.captcha()
ctx.body = captcha
ctx.type = 'image/png'
// need open the egg-session plugin
ctx.session.captcha = txt
}
// {app_root}/service/user.js
async captcha() {
const {app} = this
const ary = app.captcha.generate()
return {captcha: ary[1], txt: ary[0]}
}
Please open an issue here.