+ # + + + + new CaptchaGenerator(options) + + +
+ + + + +Initatiates the creation of captcha image generation.
+Parameters:
+ +Name | + + +Type | + + + + + +Description | +
---|---|---|
options |
+
+
+ + + +object + + + + | + + + + + +Options for constructor. |
+
height |
+
+
+ + + +integer + + + + | + + + + + +Height of captcha image. |
+
width |
+
+
+ + + +integer + + + + | + + + + + +Width of captcha image. |
+
-
+
+
+
+
+
- Since: +
- 2.0.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ View Source + + main.js, line 32 + +
+ +Example
+ + +const captcha = new CaptchaGenerator({height: 200, width: 600});
+
+
+
+
+ Members
++ # + + + text + + +
+ + + + +Get the text of captcha.
+-
+
+
+
+
+
- Since: +
- 2.0.3
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ View Source + + main.js, line 85 + +
+ +Methods
++ # + + + async + + + + + generate() → {Promise.<Buffer>} + + +
+ + + + +Method which returns image buffer
+-
+
+
+
+
+
- Since: +
- 2.0.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ View Source + + main.js, line 190 + +
+ +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)
+
+
+
++ # + + + + generateSync(optionsopt) + + +
+ + + + +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.
Parameters:
+ +Name | + + +Type | + + +Attributes | + + + + +Description | +
---|---|---|---|
options |
+
+
+ + + +object + + + + | + + +
+
+ <optional> + + + + + + |
+
+
+
+
+ Options to add extra values |
+
background |
+
+
+ + + +Image + + + + | + + +
+
+ <optional> + + + + + + |
+
+
+
+
+ Add background image. |
+
-
+
+
+
+
+
- Since: +
- 2.2.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ View Source + + main.js, line 273 + +
+ +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);
+
+
+
++ # + + + + setBackground(image) + + +
+ + + + +Set background for captcha image.
+Parameters:
+ +Name | + + +Type | + + + + + +Description | +
---|---|---|
image |
+
+
+ + + +buffer + + + + | + + + + + +Buffer/url/path of image. |
+
-
+
+
+
+
+
- Since: +
- 2.0.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ View Source + + main.js, line 121 + +
+ +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)
+
+
+
++ # + + + + setCaptcha(options) + + +
+ + + + +Change captcha text options
+Parameters:
+ +Name | + + +Type | + + + + + +Description | +
---|---|---|
options |
+
+
+ + + +SetCaptchaOptions + + + + | + + + + + +Captcha appearance options. |
+
-
+
+
+
+
+
- Since: +
- 2.0.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ View Source + + main.js, line 139 + +
+ +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)
+
+
+
++ # + + + + setDecoy(options) + + +
+ + + + +Change decoy options
+Parameters:
+ +Name | + + +Type | + + + + + +Description | +
---|---|---|
options |
+
+
+ + + +SetDecoyOptions + + + + | + + + + + +Decoy characters customisation options |
+
-
+
+
+
+
+
- Since: +
- 2.0.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ View Source + + main.js, line 173 + +
+ ++ # + + + + setDimension(height, width) + + +
+ + + + +set dimension for your captcha image
+Parameters:
+ +Name | + + +Type | + + + + + +Description | +
---|---|---|
height |
+
+
+ + + +integer + + + + | + + + + + +Height of captcha image. |
+
width |
+
+
+ + + +integer + + + + | + + + + + +Width of captcha image. |
+
-
+
+
+
+
+
- Since: +
- 2.0.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ View Source + + main.js, line 103 + +
+ +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)
+
+
+
++ # + + + + setTrace(options) + + +
+ + + + +Change trace creation options.
+Parameters:
+ +Name | + + +Type | + + + + + +Description | +
---|---|---|
options |
+
+
+ + + +SetTraceOptions + + + + | + + + + + +Trace Line appearance options. |
+
-
+
+
+
+
+
- Since: +
- 2.0.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ View Source + + main.js, line 164 + +
+ +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)
+
+
+
+