北漂IT民工 的博客

nodejs验证码生成与环境配置

首先安装系统:

1
2

sudo apt-get install libpangocairo-1.0-0 libcairo2-dev libgnomeui-dev libgstreamer0.10-dev libglib2.0-dev libjpeg-dev libgif-dev

然后再安装npm

1
2

npm install --save simple-captcha
1
2
3
4
5
6
7
8
9
10
11
12


var simpleCaptcha = require('simple-captcha');

captcha: function(req, res) {
var captcha = require('simple-captcha').create({width: 100, height: 40});
req.session.captcha = captcha.text();
console.log(req.session.captcha);
captcha.generate();
res.write(captcha.buffer('image/png'));
res.end();
}