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

ppfun-captcha

v1.6.7

Published

Generate single-path svg captcha in node.js or express.js

Downloads

197

Readme

ppfun-captcha

NPM Version

Generate single-path svg captcha in node.js

sample image

default captcha image:

image

with using fill instead of stroke:

image2

galary of generated captchas (bulk converted to png to display):

image3 image4

Origin

Credits go to the original author produck. This is a fork with added features and fixes for svg-captcha which didn't merge important Bugfixes and is at the current published state cracked. If you want the original svg-capcha, check out svg-captcha-fixed.

useful if you

  • cannot or do not want to use google recaptcha
  • have issue with install c++ addon

install

npm install ppfun-captcha

usage

var svgCaptcha = require('ppfun-captcha');

var captcha = svgCaptcha.create();
console.log(captcha);
// {data: '<svg.../svg>', text: 'abcd'}

with express

var svgCaptcha = require('svg-captcha');

app.get('/captcha', function (req, res) {
	var captcha = svgCaptcha.create();
	req.session.captcha = captcha.text;
	
	res.type('svg');
	res.status(200).send(captcha.data);
});

API

svgCaptcha.create(options)

Get a random string of four characters and corresponding svg captcha.

  • size: 4 // size of random string
  • ignoreChars: '0o1i' // filter out some characters like 0o1i
  • background: '#cc9966' // background color of the svg image
  • stroke: 'black' // style/color of the svg path stroke
  • fill: 'black' // style/color of the svg strokes fill
  • style: '' // svg path style attribute, i.e.: 'stroke-width: 4;'
  • font: Font object (see svgCaptcha.loadFont) or Array of multiple Font objects

Options that change the variation of the path:

  • `nodeDeviation: 0.1
  • truncateLineProbability: 0.5
  • truncateCurveProbability: 0.5
  • truncateCurvePositionMin: 0.4
  • truncateCurvePositionMax: 0.6
  • connectionPathDeviation : 10.0

(when using fill, set connectionPathDeviation far lower as it covers parts of the paths and is harder for humans to read - and consider converting it to PNG before serving, to stop bots from being able to read those obstructed paths)

This function returns an object that has the following property:

  • data: string // svg path data
  • 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.createCaptcha(text, options)

return a svg captcha based on text provided.
Options same as create. Returns svg string.

svgCaptcha.loadFont(url)

Load your own font.

  • url: string // path to your font Returns a Font object which you can use in options. (this api is a wrapper around loadFont api of opentype.js) Your may need experiment around various options to make your own font accessible.

svgCaptcha.options

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

In addition to size, 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

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

FAQ

This has to be a joke. /<text.+>;.+</text>/g.test...

svg captcha uses opentype.js underneath, which means that there is no '<text>1234</text>'.
You get '<path fill="#444" d="M104.83 19.74L107.85 19.74L112 33.56L116.13 19.74L119.15 19.74L113.48 36.85...'
instead.

Why no noise line option?

Noise lines can be easily filtered by path length and we decided to rather join characters with random paths, in order to to make the whole svg one single continuous path, which has the same purpose.

Why no colors?

Colors don't add any security and can be easily changed to black & white anyway. The color of the stroke and fill can be manually choosen if it is neccessary for custom styles.

License

MIT