tyrcode-captcha
Version:
仿写验证码
24 lines (22 loc) • 835 B
JavaScript
/**
* 随机生成SVG验证码
* @returns Object
*/
function create(color1='grey',color2='black',footsize='16')
{
let str = '0123456789abcdeJKNBVfghiFYTUGIHKkdsfFHGHKJas'
let one = Math.floor( Math.random() * (str.length-1-0+1)+0 )
let two = Math.floor( Math.random() * (str.length-1-0+1)+0 )
let three = Math.floor( Math.random() * (str.length-1-0+1)+0 )
let four = Math.floor( Math.random() * (str.length-1-0+1)+0 )
let text = '' + str[one] + str[two] + str[three] + str[four]
return {
text,
data: `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100px" height="50px" style="background:${color1}">
<text x="30" y="30" font-size="${footsize}px" fill=${color2} stroke="black">${text}</text>
</svg>`
}
}
module.exports = {
create,
}