示例代碼:
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