
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
captcha-canvas
Advanced tools
This is an npm package captcha-canvas helps you to make custom captcha of all types. The package uses canvas
to create captcha imagas. See installation section to know how to install.
Install canvas before captcha-canvas installation. As canvas is the peer dependencies.
Here is a quick example on how to use the module. But a well written documentation is available to understand all the mothods and customisation available for your project.
const { CaptchaGenerator } = require('captcha-canvas'); //require package here
const fs = require('fs'); //require fs module for saving image in a file
const options = {height: 200, width: 600}; //options for captcha image
const captcha = new CaptchaGenerator(options); //getting captcha constructor
captcha.text; //returns text of the captcha image.
const buffer = await captcha.generate(); //returns buffer of the captcha image
fs.writeFileSync('image.png', buffer); //will create image.png file of the captcha
You can use many methods like setCaptcha and setTrace to customize there appearance and values.
You can now apply different styles to different segments of the captcha string by passing an array of SetCaptchaOptions
to the setCaptcha
method. Each object in the array can define start
and end
properties to specify the character range it applies to.
const { CaptchaGenerator } = require('captcha-canvas');
const fs = require('fs');
(async () => {
const captcha = new CaptchaGenerator();
captcha.setCaptcha([
{ text: 'AB', color: 'red', size: 60, start: 0, end: 2 },
{ text: 'CD', color: 'green', size: 40, start: 2, end: 4 },
{ text: 'EF', color: 'blue', size: 50, start: 4, end: 6 },
])
.setDimension(150, 450);
fs.writeFileSync('./examples/segmented_captcha.png', captcha.generateSync());
console.log(captcha.text);
})();
I am working on a simple guide for this npm package you can check it out here.
Open an issue if you need help regarding this module or want to report any bug.
Star the github repo of the project. More stars motivate me to work on this project.
Open an issue to recommend some new features or report bug regarding this module.
For now, you don't have anyway to fund this project but maybe in future I update this.
We always recommend you to use the most latest version for more methods and better performance.
If you are at v1.x.y and I launched a new version 2.0.0 do not update it. Because it is major change which may (basically always) break your present code or the output is not as expected.
If you are at same major change version but a new patch/minor changed version is available install without any fear. Usually minor change comes with some new methods, and patch release comes with bug fixes/updated readme.
Thanks goes to these wonderful people (emoji key):
Shashank 📆 | TheDeadCraftPT 🐛 | IchiiDev 🐛 | Ikramullah 📖 💻 | ryanhex53 💻 |
This project follows the all-contributors specification. Contributions of any kind welcome!
FAQs
A captcha generator by using canvas module.
The npm package captcha-canvas receives a total of 4,406 weekly downloads. As such, captcha-canvas popularity was classified as popular.
We found that captcha-canvas demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.