npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kuankuan/more-complex-image-captcha

v1.0.2

Published

Used to generate more complex image captchas

Downloads

91

Readme

more-complex-image-captcha

Generating image captchas in Node.js

About svg-captcha

This project forks the code from svg-captcha and extends and optimizes it to generate more complex image captchas.

Translations

Features

  • Random rotation, scaling, and movement for individual characters
  • Utilizes sharp for PNG formatting
  • Adds Gaussian noise on top of PNGs
  • Customizable thickness for noise lines
  • Fine-grained color management using the color library
  • Developed entirely in TypeScript for easy maintenance and extension
  • Parses SVG strings using fast-xml-parser, moving beyond simple string concatenation

Installation

npm i @kuankuan/more-complex-image-captcha

Usage

Compatible with svg-captcha

const svgCaptcha = require('@kuankuan/more-complex-image-captcha');

const captcha = svgCaptcha.create(); // The create method is an alias for createSVG, kept for compatibility with svg-captcha
console.log(captcha);
// {data: '<svg.../svg>', text: 'abcd'}

Sharp Interface

const svgCaptcha = require('@kuankuan/more-complex-image-captcha');

const captchaImage = svgCaptcha.createImage();
console.log(captchaImage);
// {image: sharp(ReadableStream), text: 'abcd'}

API

svgCaptcha.create(options)

Extends the original svg-captcha with additional features.

New in more-complex-image-captcha

type Options = {
  ... // Other svg-captcha parameters
  noiseWidth?: number; // Width of noise lines
  decimalPlaces?: number; // Precision of SVG path coordinates
  colorSimilarityLimit?: number; // Limit for color similarity (0-1.1)
  disturbance?: {
    move?: {
      x?: {min?: number; max?: number}; // Defaults: -10, 10
      y?: {min?: number; max?: number}; // Defaults: -5, 5
    };
    rotate?: {min?: number; max?: number}; // Defaults: -90, 90
    scale?: {
      x?: {min?: number; max?: number}; // Defaults: 0.6, 1
      y?: {min?: number; max?: number}; // Defaults: 0.6, 1
    };
  };
};

Compatibility with svg-captcha

If no options are provided, the SVG image will have 4 characters by default.

  • size: 4 // Length of captcha
  • ignoreChars: '0o1i' // Excluded characters in captcha
  • noise: 1 // Number of 干扰 lines
  • color: true // Whether captcha characters have color; defaults to no color unless a background is set
  • background: '#cc9966' or Color object // Background color of captcha image

The returned object has the following properties:

  • data: string // SVG path data
  • text: string // Captcha text

svgCaptcha.createImage(options)

Adds an extra parameter to svgCaptcha.create:

type ImageOptions = {
  ... // Other parameters
  noisePoint?: {
    mean?: number;
    sigma?: number;
    enable?: boolean;
  };
};

The returned object includes:

  • image: sharp (ReadableStream) // sharp object for image manipulation
  • text: string // Captcha text

svgCaptcha.createMathExpr(options)

Similar to create api, you have the above options plus 3 additional:

  • mathMin: 1 // the minimum value the math expression can be
  • mathMax: 9 // the maximum value the math expression can be
  • mathOperator: + // The operator to use, +, - or +- (for random + or -)

This function returns an object that has the following property:

  • data: string // svg of the math expression
  • text: string // the answer of the math expression

svgCaptcha.loadFont(url)

Load your own font and override the default font.

  • url: string // path to your font This api is a wrapper around loadFont api of opentype.js. Your may need experiment around various options to make your own font accessible. See the following api.

svgCaptcha.options

Gain access to global setting object. It is used for create and createMathExpr api as the default options.

In addition to size, noise, color, and background, you can also set the following property:

  • width: number // width of captcha
  • height: number // height of captcha
  • fontSize: number // captcha text size
  • charPreset: string // random character preset

svgCaptcha.randomText([size|options])

return a random string.

svgCaptcha(text, options)

return a svg captcha based on text provided.

In pre 1.1.0 version you have to call these two functions, now you can call create() to save some key strokes ;).

License

MIT