Home

Note: for v3 (skia-canvas) doumentation click here.

Getting Started

To start using this npm module. We first need to install it from npm by using command npm install captcha-canvas.

Now require this package in your file where you want to create captcha.

const { CaptchaGenerator } = require("captcha-canvas");

We can see here we get CaptchaGenerator class from the module. Now initiate the constructor to start using it.

const { CaptchaGenerator } = require("captcha-canvas");
const captcha = new CaptchaGenerator();

Now we can use all the methods documented here to customize captcha according to our need.

Like if we want to use different dimension. We can use setDimension method.

const { CaptchaGenerator } = require("captcha-canvas");
const captcha = new CaptchaGenerator()
.setDimension(150, 450) 

If we want to change captcha text or its appearance, then we can use setCaptcha method.

const { CaptchaGenerator } = require("captcha-canvas");
const captcha = new CaptchaGenerator()
.setDimension(150, 450) 
.setCaptcha({text: "CUSTOM05", size: 60, color: "deeppink"})

If we want to change appearance of background text (i.e decoy). We can do that easily by using setDecoy method.

const { CaptchaGenerator } = require("captcha-canvas");
const captcha = new CaptchaGenerator()
.setDimension(150, 450) 
.setCaptcha({text: "CUSTOM05", size: 60, color: "deeppink"})
.setDecoy({opacity: 0.5})

You can also customise trace line and add background by using setTrace and setBackground method.

Once you customised everything according to your need then just you can get buffer from generateSync method. And use that buffer to display image in your project.

const { CaptchaGenerator } = require("captcha-canvas");
const captcha = new CaptchaGenerator()
.setDimension(150, 450) 
.setCaptcha({text: "CUSTOM05", size: 60, color: "deeppink"})
.setDecoy({opacity: 0.5})
.setTrace({color: "deeppink"});
const buffer = captcha.generateSync();

Final Output

captcha

Support

To get help related to this module open an issue in the github repository.