This relies on a native module called node-canvas. You will need to install cairo, so read https://github.com/learnboost/node-canvas/wiki before installing.
var captchagen = require('captchagen');
// optional object arg with keys: height, width, text, font
var captcha = captchagen.create();
captcha.text(); // Returns captcha text (randomly generated by default)
captcha.height(); // Returns captcha height (150 by default)
captcha.width(); // Returns captcha width (300 by default)
captcha.generate(); // Draws the image to the canvas
/* call `generate()` before running the below */
captcha.uri(cb); // outputs png data-uri. works sync and async (cb is optional)
captcha.buffer(cb); // outputs png buffer. works sync and async (cb is optional)
captcha.buffer(type); // outputs an image stream. type can be either png or jpeg (png is the default)
The whole thing is a middleware stack. When you use .create() it uses our default settings which look like this:
captcha.use(drawBackground);
captcha.use(drawLines);
captcha.use(drawText);
captcha.use(drawLines);
To add your own look at the middle folder in lib. You take a canvas in, modify it, and output it again.