您的位置:首页 > Web前端 > Node.js

node.js利用captchapng模块实现图片验证码

2017-05-17 18:15 726 查看
 
安装captchapng模块

npm install captchapng


 

nodejs中使用

var express = require('express');
var captchapng = require('captchapng');

//验证码
exports.verify= function(req, res, next) {
var code = parseInt(Math.random() * 9000 + 1000);
req.session.checkcode = code;
var p = new captchapng(100, 30, code);
p.color(0, 0, 0, 0);
p.color(80, 80, 80, 255);
var img = p.getBase64();
var imgbase64 = new Buffer(img, 'base64');
res.writeHead(200, {
'Content-Type': 'image/png'
});
res.end(imgbase64);
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: