码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2017-05-14 18:51:16      阅读:322      评论:0      收藏:0      [点我收藏+]

标签:span   cti   ima   使用   bsp   new   dom   code   express   

 

安装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);
}

 

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

标签:span   cti   ima   使用   bsp   new   dom   code   express   

原文地址:http://www.cnblogs.com/fangdong/p/6853124.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!