Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

createCaptcha

FuntyGithub edited this page Apr 19, 2022 · 2 revisions

This function lets you create a captcha.

captcha function arguments:

ALL arguments are optional but they can personalize the result captcha!

Example:

const captcha = await createCaptcha({
  length: 5,
  bgColor: "#00000000",
  bgColorDiff: {R: 20, G: 20, B: 20},
  decoys: {amount: 40, sizeMin: 10, sizeMax: 25},
  randomCharOrder: true,
  characters: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()",
  width: 600,
  height: 400,
  minCharacterSize: 30,
  maxCharacterSize: 100,
  characterColor: "#FF0000",
  lineColor: "#00FF00",
  decoyColor: "#0000FF"
});

captcha function arguments:

length

Name: length
Type: Number
Default: 5
Description: how many characters the captcha should have

bgColor

Name: bgColor
Type: String
Default: random (could be bad for people with colorblindness)
Description: Background color of the captcha

bgColorDiff

Name: bgColorDiff
Type: Object
Default: {R: 20, G: 20, B: 20}

Sub-Option Type Description Default (value if you don't give any)
R Number the minimum difference between Red in the colorcode of the characters 20
G Number the minimum difference between Green in the colorcode of the characters 20
B Number the minimum difference between Blue in the colorcode of the characters 20

decoys

Name: decoys
Type: Object
Default: {amount: 40, sizeMin: 10, sizeMax: 25}

Sub-Option Type Description Default (value if you don't give any)
amount Number the amount of decoys to add 40
sizeMin Number the minimum of the random character size for the decoys 10
sizeMax Number the maximum of the random character size for the decoys 10

characters

Name: characters
Type: String
Default: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()'
Description: the characters that the image is allowed to include

randomCharOrder

Name: randomCharOrder
Type: Boolean
Default: true
Description: if it should pick random characters out of the provided string. If you want a custom, non-random string, the length should be equal to the string argument length

width

Name: width
Type: Integer
Default: 600
Description: sets the minimum size of the canvas in the X direction

height

Name: height
Type: Integer
Default: 400
Description: sets the minimum size of the canvas in the Y direction

minCharacterSize

Name: minCharacterSize
Type: Integer
Default: 30
Description: sets the minimum size of each character. Sometimes if the length value is too high the characters can be too small to read

maxCharacterSize

Name: maxCharacterSize
Type: Integer
Default: undefined
Description: sets the maximum size of each character. Recommended to set if length is small.

characterColor

Name: characterColor
Type: String
Default: undefined
Description: sets the character color for each character to the specified hex code. Use undefined to use a randomly generated color for each character

lineColor

Name: lineColor
Type: String
Default: undefined
Description: sets the line color for to the specified hex code. Use undefined to use a randomly generated color

decoyColor

Name: decoyColor
Type: String
Default: undefined
Description: sets the decoy color for to the specified hex code. Use undefined to use the lineColor

Clone this wiki locally