jacket-captcha
A captcha that develop by Jacket Chen..
Sample
The generated captcha image looks like this:
Usage
First, install jacket-captcha
.
npm install jacket-captcha
jacket-captcha
depend on node-canvas
, install node-canvas
you'll need Cairo. For system-specific installation view the Wiki.
You can quickly install the dependencies by using the command for your OS:
OS | Command |
---|---|
OS X | brew install pkg-config cairo libpng jpeg giflib |
Ubuntu | sudo apt-get install libcairo2-dev libjpeg8-dev libpango1.0-dev libgif-dev build-essential g++ |
Fedora | sudo yum install cairo cairo-devel cairomm-devel libjpeg-turbo-devel pango pango-devel pangomm pangomm-devel giflib-devel |
Solaris | pkgin install cairo pkg-config xproto renderproto kbproto xextproto |
Windows | Instructions on wiki |
El Capitan users: If you have recently updated to El Capitan and are experiencing trouble when compiling, run the following command: xcode-select --install
. Read more about the problem on Stack Overflow.
After you sucessfully install jacket-captcha
, use it in your node app:
// require libraryvar captcha = ; // configure and create a captcha imagevar captchaObj = captcha; // get the captcha codevar code = captchaObjcode; // get the base64 url of the captcha imagevar base64URL = captchaObjbase64URL; // save the captcha image, you could specify the image's name and where to store itcaptchaObj; // Do something...
API
require jacket-captcha
will return a captcha instance.
Captcha#config(options)
Return: Object
This method will return the captcha instance.
options
Type: Object
The configuration of the captcha instance.
options.width
Type: Number
Config the width of the captcha image.
options.height
Type: Number
Config the height of the captcha image.
options.lineNumber
Type: Number
Config the number of lines that would be drawn into the image in case of prevent the program automatically discern the code on the image.
options.charNumber
Type: Number
Config the length of code.
Captcha#create()
Return: Object
Create a captcha image.
This method will return the captcha image instance.
Captcha#getCode()
Return: String
Get the captcha code.
This method will return the captcha code that generated by the method of Captcha#create()
.
Captcha#getBase64URL()
Return: String
Get the base64 url of the captcha image.
This mehod will return the base64 url of the captcha image that generated by the method of Captcha#create()
.
Captcha#save(options)
options
Type: Object
Specify the name of the saved image and where to store it.
options.dirname
Type: String
The directory where to store the image.
options.filename
Type: String
The name of the saved image.