Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Likogann committed Feb 22, 2023
0 parents commit 9e906ca
Show file tree
Hide file tree
Showing 15 changed files with 943 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# NodeJS
node_modules/

# Misc
image.png
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# image-captcha
NodeJS captcha image generator. This is a very basic captcha generator. It would be best used on an onion site or related. For clearnet sites, or other more proffesional applications, please look into Cloudflare's hCaptcha.
<br>
The default image size is 400x200px.

#### Installing
```bash
npm install @likogann/image-captcha
```
#### Including
```js
const { genCaptcha, genCaptchav2, genImgFromBuffer } = require('@likogann/image-captcha')
```

# Generating a Captcha
To generate a captcha, run the `genCaptcha()` or `genCaptchav2()` function.
```js
let captcha = genCaptcha()
```
When generating a Captcha, the function will return the PNG buffer, and the content of the captcha.
```json
{
png: <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 01 90 00 00 00 c8 08 06 00 00 00 c6 15 b7 e2 00 00 00 06 62 4b 47 44 00 ff 00 ff 00 ff a0 bd a7 ... 7120 more bytes>,
text: 'YYASBK'
}
```

## Translating Buffer to PNG
The PNG buffer of the captcha, and the desired image path are required. Passing those two variables will result in an image being written.
```js
genImgFromBuffer(captcha.png, "./image.png")
```

## Captcha v2
CaptchaV2 uses significantly more resources, but is significantly harder to read. CaptchaV2 generates the text to be the same colour as the background, using the random lines and boxes to reveal the text.

## Custom Image Generation
You can change everything about the captcha generation. The following variables are accepted. If the variable isn't included, it will use the default value.
```js
// ## Base Image
let configIn.width = 400;
let configIn.height = 200;
let configIn.textColour = "#" + Math.floor(Math.random()*16777215).toString(16);
let configIn.bgColour = "#" + Math.floor(Math.random()*16777215).toString(16);
// ## Obfuscation
let configIn.lineWidth = 3;
let configIn.lines = Math.random()*200; // Math.random()*200;
let configIn.shapes = Math.random()*200; // Math.random()*200;
let configIn.shapesSizeMultiplier = 80
// ## Text size, length, and rotation
let configIn.fontsize = 40;
let configIn.charLength = 6;
let configIn.rotatemax = 20;
let configIn.rotatemin = -20;

let captcha = genCaptcha(configIn)
let captchav2 = genCaptchav2(configIn)
```
5 changes: 5 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let { genCaptcha, genCaptchav2, genImgFromBuffer } = require('./index.js')
let captcha = genCaptchav2()

console.log(captcha)
genImgFromBuffer(captcha.png, "image.png")
Binary file added examples/dkbrown-goldbg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/gold-dkbluebg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/gold-pinkbg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/lime-hlpurplebg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/white-purplebg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fonts/OpenSans-Regular.ttf
Binary file not shown.
19 changes: 19 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = { genCaptcha, genCaptchav2, genImgFromBuffer };

// generateCaptchav1.js
function genCaptcha(config) {
let genCaptcha = require('./src/generateCaptcha.js');
return genCaptcha(config);
};

// generateCaptchav2.js
function genCaptchav2(config) {
let genCaptchav2 = require('./src/generateCaptchav2.js');
return genCaptchav2(config);
};

// generateImageFromBuffer.js
function genImgFromBuffer(buf, path) {
let genImgFromBuffer = require('./src/generateImageFromBuffer.js');
return genImgFromBuffer(buf, path);
};
Loading

0 comments on commit 9e906ca

Please sign in to comment.