Skip to content

ddededodediamante/captcha-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

captcha-generator

A highly customizable CAPTCHA generator using canvas in TypeScript.

Installation

npm install @ddededodediamante/captcha-generator

Usage

import Captcha from '@ddededodediamante/captcha-generator';
import fs from 'fs';

const captcha = new Captcha({
  width: 250,
  height: 100,
  backgroundColor: '#f0f0f0',
  textColor: '#333',
  font: 'Arial',
  fontSize: 40
});

const { text, buffer } = captcha.generate("image/png");
console.log('CAPTCHA text:', text);
fs.writeFileSync('captcha.png', buffer);

API

new Captcha(options?)

Creates a CAPTCHA generator with optional settings:

Option Type Default Description
width number 200 Canvas width in pixels
height number 80 Canvas height in pixels
backgroundColor string #ffffff Background color
textColor string #000000 Color of the CAPTCHA text
font string Sans Font family
fontSize number 32 Font size in pixels
characters string ABCDEFGHI... Characters used in the CAPTCHA text
charLength number 6 Number of characters in the CAPTCHA
noiseLines number 4 Number of random noise lines
noiseDots number 100 Number of random noise dots
noiseColor string #888888 Color for noise lines and dots

generate(mime?, quality?)

Generates the CAPTCHA, returns { text: string; buffer: Buffer }.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published