svg-captcha icon indicating copy to clipboard operation
svg-captcha copied to clipboard

how to change font color (without randomizing)?

Open petkovic43 opened this issue 7 years ago • 2 comments

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

petkovic43 avatar Dec 19 '17 11:12 petkovic43

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

Leoword avatar Jul 25 '18 10:07 Leoword

可以在源码中更改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;

};`

820465323 avatar Aug 05 '19 03:08 820465323