|
|
|
@ -5,25 +5,6 @@ const optionMngr = require('./option-manager');
|
|
|
|
|
|
|
|
|
|
const opts = optionMngr.options;
|
|
|
|
|
|
|
|
|
|
const getLineNoise = function (width, height, options) {
|
|
|
|
|
const hasColor = options.color;
|
|
|
|
|
const noiseLines = [];
|
|
|
|
|
const min = options.inverse ? 7 : 1;
|
|
|
|
|
const max = options.inverse ? 15 : 9;
|
|
|
|
|
let i = -1;
|
|
|
|
|
|
|
|
|
|
while (++i < options.noise) {
|
|
|
|
|
const start = `${random.int(1, 21)} ${random.int(1, height - 1)}`;
|
|
|
|
|
const end = `${random.int(width - 21, width - 1)} ${random.int(1, height - 1)}`;
|
|
|
|
|
const mid1 = `${random.int((width / 2) - 21, (width / 2) + 21)} ${random.int(1, height - 1)}`;
|
|
|
|
|
const mid2 = `${random.int((width / 2) - 21, (width / 2) + 21)} ${random.int(1, height - 1)}`;
|
|
|
|
|
const color = hasColor ? random.color() : random.greyColor(min, max);
|
|
|
|
|
noiseLines.push(`<path d="M${start} C${mid1},${mid2},${end}" stroke="${color}" fill="none"/>`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return noiseLines;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getText = function (text, width, height, options) {
|
|
|
|
|
const len = text.length;
|
|
|
|
|
const spacing = (width - 2) / (len + 1);
|
|
|
|
@ -58,8 +39,7 @@ const createCaptcha = function (text, options) {
|
|
|
|
|
const bgRect = bg ?
|
|
|
|
|
`<rect width="100%" height="100%" fill="${bg}"/>` : '';
|
|
|
|
|
const paths =
|
|
|
|
|
[].concat(getLineNoise(width, height, options))
|
|
|
|
|
.concat(getText(text, width, height, options))
|
|
|
|
|
[].concat(getText(text, width, height, options))
|
|
|
|
|
.sort(() => Math.random() - 0.5)
|
|
|
|
|
.join('');
|
|
|
|
|
const start = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0,0,${width},${height}">`;
|
|
|
|
|