node.js生成验证码及图片

示例代码:

var svgCaptcha = require('svg-captcha');
var fs = require('fs');

var codeConfig = {
    size: 5,// 验证码长度
    ignoreChars: '0o1i', // 验证码字符中排除 0o1i
    noise: 2, // 干扰线条的数量
    height: 44 
}
var captcha = svgCaptcha.create(codeConfig);
fs.writeFileSync('test.png', captcha.data);
console.log(captcha.text.toLowerCase());

运行结果:

$ node test.js
y34sh

生成的图片:

这个功能主要用于在Express中生成验证码,参考链接:https://blog.csdn.net/qq_28027903/article/details/78656333

原文地址:https://www.cnblogs.com/zifeiy/p/10947287.html