produck / svg-captcha

generate svg captcha in node
MIT License
1.86k stars 174 forks source link

how to change font color (without randomizing)? #16

Open petkovic43 opened 6 years ago

petkovic43 commented 6 years ago

How to put all the characters in blue (or red) color while holding the white background?

Leoword commented 6 years ago

If you don't want the randomizing font color , you can define the generate of captcha yourself in version 2.0.0

820465323 commented 5 years ago

可以在源码中更改lib/index.js文件中的getText方法, `const getText = function (text, width, height, options) { const len = text.length; const spacing = (width - 2) / (len + 1); const min = options.inverse ? 10 : 0; const max = options.inverse ? 14 : 4; let i = -1; const out = [];

while (++i < len) {
    const x = spacing * (i + 1);
    const y = height / 2;
    const charPath = chToPath(text[i], Object.assign({x, y}, options));

    // const color = options.color ?
    //  random.color(options.background) : random.greyColor(min, max);
    const color = random.greyColor(min, max);//使用默认字体颜色,也可以使用random.color(options."#586069");自定义颜色 
    out.push(`<path fill="${color}" d="${charPath}"/>`);
}

return out;

};`