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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM