-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
543bba0
commit c107b5b
Showing
14 changed files
with
510 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/// <reference types="node" /> | ||
import { Canvas, CanvasRenderingContext2D, Image } from "skia-canvas"; | ||
import { SetCaptchaOption, SetDecoyOption, SetTraceOption } from "./constants"; | ||
/** | ||
* Captcha Generator | ||
*/ | ||
export declare class Captcha { | ||
protected _height: number; | ||
protected _width: number; | ||
protected _captcha: SetCaptchaOption; | ||
protected _trace: SetTraceOption; | ||
protected _decoy: SetDecoyOption; | ||
protected _canvas: Canvas; | ||
protected _ctx: CanvasRenderingContext2D; | ||
protected _coordinates: number[][]; | ||
async: Boolean; | ||
/** | ||
* Start captcha image creation. | ||
* @param {number} [width] Width of captcha image. | ||
* @param {number} [height] Height of captcha image. | ||
* @constructor | ||
*/ | ||
constructor(width?: number, height?: number); | ||
/** | ||
* Get Captcha text. | ||
* @returns {string} Get captcha text. | ||
*/ | ||
get text(): string; | ||
/** | ||
* Get png image of captcha. | ||
* @returns {Buffer} Get png image of captcha created. | ||
*/ | ||
get png(): Buffer; | ||
/** | ||
* Draw image on your captcha. | ||
* @param {Image} image Choose image you want to add. | ||
* @returns {Captcha} | ||
*/ | ||
drawImage(image: Image): Captcha; | ||
/** | ||
* Add decoy on your captcha image. | ||
* @param {SetDecoyOptions} [decoyOption] Decoy option you want to customise | ||
* @returns {Captcha} | ||
*/ | ||
addDecoy(decoyOption?: SetDecoyOption): Captcha; | ||
/** | ||
* Draw trace line over your captcha. | ||
* | ||
* Note: If you want to use custom text or change size of captcha text then drawCaptcha before drawTrace. | ||
* @param {SetTraceOptions} [traceOption] | ||
* @returns {Captcha} | ||
*/ | ||
drawTrace(traceOption?: SetTraceOption): Captcha; | ||
/** | ||
* Draw captcha text on captcha image. | ||
* @param {SetCaptchaOptions} [captchaOption] | ||
* @returns {Captcha} | ||
*/ | ||
drawCaptcha(captchaOption?: SetCaptchaOption): Captcha; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/// <reference types="node" /> | ||
import { Image } from "skia-canvas"; | ||
import { Captcha } from "./captcha"; | ||
import { SetCaptchaOption, SetDecoyOption, SetTraceOption } from "./constants"; | ||
interface ConstructorOption { | ||
width?: number; | ||
height?: number; | ||
} | ||
/** | ||
* Captcha Generator. | ||
*/ | ||
export declare class CaptchaGenerator extends Captcha { | ||
private background?; | ||
/** | ||
* Initatiates the creation of captcha image generation. | ||
* @example const captcha = new CaptchaGenerator({height: 200, width: 600}); | ||
* @param {object} options Options for constructor. | ||
* @param {integer} options.height Height of captcha image. | ||
* @param {integer} options.width Width of captcha image. | ||
* @since 2.0.0 | ||
*/ | ||
constructor(options?: ConstructorOption); | ||
/** | ||
* Get Captcha text. | ||
* @returns {string} Get captcha text. | ||
*/ | ||
get text(): string; | ||
/** | ||
* Change captcha text options | ||
* @param {SetCaptchaOptions} options Captcha appearance options. | ||
* @example | ||
* const { CaptchaGenerator } = require("captcha-canvas"); | ||
* const fs = require("fs") | ||
* const captcha = new CaptchaGenerator(); | ||
* const options = {font: "Comic Sans", size: 60} | ||
* captcha.setCaptcha(options) | ||
* const buffer = await captcha.generate() //generate image | ||
* | ||
* fs.writeFileSync("image.png", buffer) | ||
* @since 2.0.0 | ||
*/ | ||
setCaptcha(captchaOption: SetCaptchaOption): CaptchaGenerator; | ||
/** | ||
* set dimension for your captcha image | ||
* @param {number} height Height of captcha image. | ||
* @param {number} width Width of captcha image. | ||
* @example | ||
* const { CaptchaGenerator } = require("captcha-canvas"); | ||
* const fs = require("fs") | ||
* const captcha = new CaptchaGenerator(); | ||
* captcha.setDimension(200, 600); | ||
* const buffer = await captcha.generate() //generate image | ||
* | ||
* fs.writeFileSync("image.png", buffer) | ||
* @since 2.0.0 | ||
*/ | ||
setDimension(height: number, width: number): CaptchaGenerator; | ||
/** | ||
* Set background for captcha image. | ||
* @param {buffer} image Buffer/url/path of image. | ||
* @example | ||
* const { CaptchaGenerator } = require("captcha-canvas"); | ||
* const fs = require("fs") | ||
* const captcha = new CaptchaGenerator(); | ||
* captcha.setBackground("./path/toFile"); | ||
* const buffer = await captcha.generate() //generate image | ||
* | ||
* fs.writeFileSync("image.png", buffer) | ||
* @since 2.0.0 | ||
*/ | ||
setBackground(image: Buffer | string): CaptchaGenerator; | ||
/** | ||
* Change trace creation options. | ||
* @param {SetTraceOptions} options Trace Line appearance options. | ||
* @example | ||
* const { CaptchaGenerator } = require("captcha-canvas"); | ||
* const fs = require("fs") | ||
* const captcha = new CaptchaGenerator(); | ||
* const options = {size: 5, color: "deeppink"} | ||
* captcha.setTrace(options) | ||
* const buffer = await captcha.generate() //generate image | ||
* | ||
* fs.writeFileSync("image.png", buffer) | ||
* @since 2.0.0 | ||
*/ | ||
setTrace(traceOption: SetTraceOption): CaptchaGenerator; | ||
/** | ||
* Change decoy options | ||
* @param {SetDecoyOptions} options Decoy characters customisation options | ||
* @since 2.0.0 | ||
*/ | ||
setDecoy(decoyOption: SetDecoyOption): CaptchaGenerator; | ||
/** | ||
* Method which returns image buffer | ||
* @async | ||
* @returns {Promise<Buffer>} | ||
* @example | ||
* const { CaptchaGenerator } = require("captcha-canvas"); | ||
* const fs = require("fs") | ||
* const captcha = new CaptchaGenerator(); | ||
* const buffer = await captcha.generate() //generate image | ||
* | ||
* fs.writeFileSync("image.png", buffer) | ||
* @since 2.0.0 | ||
*/ | ||
generate(): Promise<Buffer>; | ||
/** | ||
* Non asynchronous method to generate captcha image. | ||
* > Note: It do not use `setBackground` method value for background image. If you want to set background | ||
* and also use generateSync method then use background option in genrateSync method. | ||
* @param {Image} [background] Add background image. | ||
* @example | ||
* const { CaptchaGenerator, resolveImage } = require("captcha-canvas"); | ||
* const fs = require("fs"); | ||
* const img = await resolveImage("./path/to/file"); | ||
* | ||
* const captcha = new CaptchaGenerator() | ||
* .generateSync(background: img); | ||
* | ||
* fs.writeFileSync("image.png", captcha); | ||
* @since 2.2.0 | ||
* @returns {Buffer} | ||
*/ | ||
generateSync(background?: Image): Buffer; | ||
} | ||
export {}; |
Oops, something went wrong.