captcha-canvas
Version:
A captcha generator by using canvas module.
89 lines (88 loc) • 3.06 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
import { SetTraceOptions, SetDecoyOptions, SetCaptchaOptions, SetDimensionOption } from './constants';
import { Image } from 'canvas';
/**
* @class CaptchaGenerator
* @description CaptchaGenerator class
* @example
* const captcha = new CaptchaGenerator();
* captcha.setDimension(150, 450);
* captcha.setCaptcha({font: "Comic Sans", size: 60});
* captcha.setDecoy({opacity: 0.5});
* captcha.setTrace({color: "blue"});
* const {buffer, text} = await captcha.generate();
*/
declare class CaptchaGenerator {
private height;
private width;
private captcha;
private trace;
private decoy;
private background?;
private captchaSegments;
/**
* @constructor
* @param {SetDimensionOption} options - Options for the captcha generator
*/
constructor(options?: SetDimensionOption);
/**
* @method text
* @description Get the captcha text
* @returns {string} The captcha text
*/
get text(): string;
/**
* @method setDimension
* @description Set the dimension of the captcha
* @param {number} height - The height of the captcha
* @param {number} width - The width of the captcha
* @returns {this} The captcha generator instance
*/
setDimension(height: number, width: number): this;
/**
* @method setBackground
* @description Set the background of the captcha
* @param {Buffer | string} image - The background image
* @returns {this} The captcha generator instance
*/
setBackground(image: Buffer | string): this;
/**
* @method setCaptcha
* @description Set the captcha options
* @param {SetCaptchaOptions | SetCaptchaOptions[]} options - The captcha options
* @returns {this} The captcha generator instance
*/
setCaptcha(options: SetCaptchaOptions | SetCaptchaOptions[]): this;
/**
* @method setTrace
* @description Set the trace options
* @param {SetTraceOptions} options - The trace options
* @returns {this} The captcha generator instance
*/
setTrace(options: SetTraceOptions): this;
/**
* @method setDecoy
* @description Set the decoy options
* @param {SetDecoyOptions} options - The decoy options
* @returns {this} The captcha generator instance
*/
setDecoy(options: SetDecoyOptions): this;
/**
* @method generate
* @description Generate the captcha image
* @returns {Promise<Buffer>} The captcha image buffer
*/
generate(): Promise<Buffer>;
/**
* @method generateSync
* @description Generate the captcha image synchronously
* @param {object} options - The options for generating the captcha
* @param {Image} options.background - The background image
* @returns {Buffer} The captcha image buffer
*/
generateSync(options?: {
background?: Image;
}): Buffer;
}
export default CaptchaGenerator;