# captcha-lite

> Lite captcha generator by Pure Javascript.

Latest version **1.1.0** (published 2017-07-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install captcha-lite
pnpm add captcha-lite
yarn add captcha-lite
bun add captcha-lite
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2017-07-28 |
| First published | 2017-07-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | ElemeFe |
| Maintainers | geemo, lellansin |
| Keywords | node-captcha, captchapng |

## Links

- npm: https://www.npmjs.com/package/captcha-lite
- Repository: https://github.com/ElemeFE/node-captcha-lite
- Homepage: https://github.com/ElemeFE/node-captcha-lite#readme
- Issues: https://github.com/ElemeFE/node-captcha-lite/issues
- npm.io page: https://npm.io/package/captcha-lite

## Dependencies (1)

- [node-pnglib](https://npm.io/package/node-pnglib.md) *

## Recent versions

- 1.1.0 (latest) — 2017-07-28
- 1.0.0 — 2017-07-28
- 0.1.3 — 2017-07-28
- 0.1.1 — 2017-07-28
- 0.1.0 — 2017-07-27
- 0.0.1 — 2017-07-27
- 0.0.0 — 2017-07-26

## README

# node-captcha-lite
Lite captcha generator by Pure Javascript.

# Usage
node-captcha-lite just extends [node-pnglib](https://github.com/Lellansin/node-pnglib), you can check its document for constructor options since we only add some public methods on it.

**Let's try to draw number:**

```javascript
'use strict';

const fs = require('fs');
const path = require('path');
const Captcha = require('..');
const FONTS = Captcha.FONTS;

function rand(min, max) {
  let comp = max - min;
  return (Math.random() * comp + min) | 0;
}

function getRandFont(fonts) {
  const fontNames = Object.keys(fonts);
  return fonts[fontNames[rand(0, fontNames.length)]];
}

let png = new Captcha(200, 100, 8, [255, 255, 255, 255]);
let chars = getRandFont(FONTS).chars;

for (let i = 0; i < chars.length; ++i) {
  let font = getRandFont(FONTS);
  let ch = chars[i];
  png.drawChar(ch, 0 + 2 * i * font.w, 50, font, '#00FF00');
}

fs.writeFileSync(path.resolve(__dirname, './char.png'), png.getBuffer());
```

Output:

![line](/example/char.png)

**Let's try to draw bezier curve:**

```javascript
'use strict';

const fs = require('fs');
const path = require('path');
const Captcha = require('..');

const png = new Captcha(300, 300, 8, [255,255,255,255]);

const bezierPoints = [
  [250, 50],
  [250, 250],
  [260, 70],
  [60, 70]
];

png.drawBezier(bezierPoints, {
  tolerance: 0, // 曲线线条扩宽的距离
  step: 1/1000, // 每两个点之间绘制1000个点
  fixEndPointCurve: true, // 是否绘制开始和结束点的曲线
  handlerRatio: 0.5, // 贝塞尔曲线的句柄长度（连续贝塞尔模型）
  color: '#cc0044' // 曲线的颜色
});

fs.writeFileSync(path.resolve(__dirname, './bezier.png'), png.getBuffer());
```

Output:

![bezier](/example/bezier.png)

---
_Source: https://npm.io/package/captcha-lite · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
