koa-canvas-captcha
v0.1.4
Published
A captcha library for koa framework
Downloads
3
Readme
koa-canvas-captcha
适用于Koa框架的canvas绘制的验证码库
Install
npm install koa-canvas-captcha --save
Demo
var captcha = require('koa-canvas-captcha');
var path = require("path");
var getCaptcha = function*(){
//生成验证码 返回text和图buffer
var item = yield captcha({
length: 4,
fontSize: 30,
width: 150,
height: 32,
color: 'green', // code color,
background: 'rgb(245,245,245)', // captcha background color
lineWidth: 0.5, // Interference lines width
type: 'normal',
fontPath: path.join(__dirname, './captchaFont.ttf')
});
//将验证码答案存在session
this.session.captcha = item.answer;
//返回图片
this.type = 'jpg';
this.set({
'Cache-Control': 'no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0',
'Expires': 'Sun, 12 Jan 1986 12:00:00 GMT'
});
this.body = item.imageBuffer
};
Options
length
- (Number ) captcha lengthfontSize
- (Number | default: 30 ) captcha font sizewidth
- (Number | default: 150) image widthheight
- (Number | default: 32) height widthlineWidth
- (Number | default: 1) background line widthbackground
- (String | default: rgb(255,255,255)) background colorcolor
- (String | default: rgb(0,0,0)) font colortext
- (String) custom captcha textfontPath
- (String ) the *.ttf file pathtype
- (String | default: normal) captcha typenormal
- random letter and numberletter
- just letternumber
- just numberarithmetic
- random arithmetic
Result
text
- the words on the captchaanswer
- the answer should inputimageBuffer
- imageBuffer