0.9.4 • Published 2 years ago

complexcaptcha v0.9.4

Weekly downloads
-
License
GNU GPL v3
Repository
github
Last release
2 years ago

Project that aims for generating captcha image with various customization options - for Node.JS


Quick look

For simply generating and saving one captcha image:

import * as fs from "fs";

import ComplexCaptcha from "complexcaptcha";

//

// generating captcha
const data = ComplexCaptcha.Generate({
    mimeType:   "image/jpeg"
});

// saving to file
fs.writeFileSync(`./captcha__${data.solution}.jpeg`), data.buffer);

Current features

  • Custom characters list (string)
  • Custom font or fonts selected randomly for each character.
  • Custom colors by creating palette of 3 colors (background, foreground, details) or providing array of palettes (random picking)
  • Displacement of individual characters on y-axis
  • Deformation of individual characters (scaling/skewing)
  • Rotation of individual characters
  • Pairing individual characters for overlaping
  • Randomly picking characters for being impostors (characters that doesn't matter in answer/solution)
  • Randomly picking font for each character.
  • Ability to disable features for individual provided fonts
  • Ability to disable characters for individual provided fonts
  • Drawing fake captcha text in background with smaller font size (dummies)
  • Drawing dirt on top of captcha (lines, xor linex/box/islands)

How to build

To build from typescript to javascript CommonJS module, just run command npm run build. You will find built code in dist directory. This command build whole module along with examples.


Examples

To run any of the examples located in examples folder:

  1. Run command npm run build for building whole module along with examples.
  2. Run command npm run example1 for running example1 program.
  3. Look at the output in output/example1 directory.

API

Registering custom font

If You want to use custom font/s, just call ComplexCaptcha.CanvasRegisterFont function with same arguments as in registerFont function in canvas module for Node.js. Read more details here: https://github.com/Automattic/node-canvas#registerfont

ComplexCaptcha.Generate

Static function ComplexCaptcha.Generate generates captcha and returns object of GeneratedCaptcha type. It takes one argument, object of GenerateOptions type.

GeneratedCaptcha

Object of GeneratedCaptcha type contains fields:

GeneratedCaptcha.Instructions

GenerateOptions

Object of GenerateOptions type may contains fields:

GenerateOptions, Palette

GenerateOptions, FontInfo/FrontFontInfo

Object of FontInfo/FrontFontInfo type contains information about font used to render text:

GenerateOptions.CharDisplacementVOptions

Object of CharDisplacementVOptions type contains information about how generator will displace vertically characters on image.

GenerateOptions.CharRotationOptions

Object of CharRotationOptions type contains information about how generator will rotate characters on image.

GenerateOptions.CharDeformationOptions

Object of CharDeformationOptions type contains information about how generator will deformate characters on image. First, a chance test will be performed, then the deformation type will be selected randomly (scaling on x or y axis, or skewing on x or y axis)

GenerateOptions.PairingOptions

Object of PairingOptions type contains information about how generator will pair characters rendered on image. Pairing is feature that randomly pair two characters into one unit, that will be rotated/deformated together and also both characters in pair will slightly overlapped for less readability and greater challange (can be customized).

GenerateOptions.ImpostorsOptions

Object of ImpostorsOptions type contains information about fake characters will be placed among real ones. User is challanged to skip fake characters when rewriting captcha. Fake characters are marked by circle colored by palette.details, but modified to be semi-transparent.

GenerateOptions.DirtOptions

Object of DirtOptions type contains information about drawings that will be put on top of whole image to make it less readable for cpu. Currently only xor box and line are avaliable and are selected randomly.

GenerateOptions.DummiesOptions

Object of DummiesOptions type contains information about smaller text units that will be put behind real text to make whole captcha less readable for cpu.

0.9.4

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.9.0

2 years ago