1.0.0 • Published 9 years ago
hahoo-captcha v1.0.0
hahoo-captcha
A nodejs captcha module based on gm and creating random pleasing colors with PleaseJS

Install
First download and install GraphicsMagick or ImageMagick. In Mac OS X, you can simply use Homebrew and do:
brew install graphicsmagick
brew install imagemagickthen use npm:
npm install hahoo-captcha --saveUsage
save(filePath, options)
save a captcha image
import captcha from 'hahoo-captcha';
captcha.save('./captcha.png', {
text: 'test',
baseColor: 'skyblue'
})
.then((code) => {
console.log(code);
})
.catch((err) => {
console.log(err);
});toBuffer(type, options)
return captcha image buffer
typeimage type (default: png)
import http from 'http';
import captcha from 'hahoo-captcha';
http.createServer((req, res) => {
captcha.toBuffer()
.then((data) => {
console.log(data.text);
res.writeHead(200, { 'Content-Type': 'image/png' });
res.write(data.buffer);
res.end();
})
.catch((err) => {
console.log(err);
});
}).listen(8080);Options
widthimage width (default: 86)heightimage height (default: 38)backgroundimage background (default: #fff)textcaptcha text (default: random a string)lengthif text is empty, will random a string automatically, this length is the length of random string. (default: 4)textXleft margin of text (default: 2)textYtop margin of text (default: 31)baseColorthe name of an HTML color(e.g. 'pink') will create a random color within the HSV range of the chosen color. if null will automatically generate a random color for captcha text.fontfont pathfontSizefont size (default: 32)wordWidthtext word width (default: 19)maxSwirlthe max degree of swirl (default: 20)lineCountthe count of random line (default: 5)lineWidththe width of random line (default: 1)dotCountthe count of random dot (default: 200)
This is use baseColor: 'skyblue' option (Please refer to HTML color):

License
MIT
1.0.0
9 years ago