Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

captcha-lite

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

captcha-lite

Lite captcha generator by Pure Javascript.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

node-captcha-lite

Lite captcha generator by Pure Javascript.

Usage

node-captcha-lite just extends 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:

'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

Let's try to draw bezier curve:

'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

Keywords

FAQs

Package last updated on 28 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc