Introduction

lua-captcha is a small lua module to generate captchas using lua-gd ( http://luaforge.net/projects/lua-gd/ )

This is version 0.2: http://projects.plentyfact.org/attachments/download/96/lua-captcha-0.2.tar.gz

Usage

A very simple example:

require 'captcha'

mycaptcha = captcha.new()
mycaptcha:font("./Vera.ttf")
cap = mycaptcha:write("out4.png")
print(cap)

mycaptcha:write() will return the random string generated for the captcha. the default length is 6 characters,
black on white background.mycaptcha:font("./Vera.ttf")

this looks even nicer using a different font, e.g. "Carbon Type":

Hoever, you can set many more options:

require 'captcha'

mycaptcha = captcha.new()
mycaptcha:font("./Vera.ttf")       -- path to the font you want to use
mycaptcha:length(10)               -- length of the captcha to generate
mycaptcha:bgcolor(0, 0, 240)       -- background color in RGB
mycaptcha:fgcolor(240,0,0)         -- foreground color in RGB
mycaptcha:line(true)               -- set "true" if you want a line across the captcha
cap = mycaptcha:write("out.png")
print(cap)

to add some scribbled lines to the background, use

require 'captcha'

mycaptcha = captcha.new()
mycaptcha:font("./carbon.ttf")       
mycaptcha:length(6)               
mycaptcha:scribble()               -- add some scribbled lines to the background, 
                                   -- you can optionally set the number of lines
                                   -- default is 20          
cap = mycaptcha:write("out.png")
print(cap)

if you do not want lua-captcha do generate a random string - i.e. you want to use words you can choose yourself - use:

require 'captcha'

mycaptcha = captcha.new()
mycaptcha:font("./bewilder.ttf")
mycaptcha:string("i love lua")
mycaptcha:bgcolor(255, 201, 51)
mycaptcha:fgcolor(255, 102, 51)
mycaptcha:line(true)
cap = mycaptcha:write("out.png")
print(cap)

How to get it

from svn:

svn co http://svn.plentyfact.org/lua-captcha

lua-captcha requires lua-gd , so you will need to install this from luarocks or fetch the source here
( http://projects.plentyfact.org/projects/lua-captcha/files ) and compile it yourself, or install it from plentyfact's debian repository ( see below )

as tarball:

http://projects.plentyfact.org/projects/lua-captcha/files

as debian package

you can also install lua captcha from the plentyfact package repos:

deb http://packages.plentyfact.org/debian/ squeeze/

or

deb http://packages.plentyfact.org/debian/ wheezy/

and install:

apt-get install liblua5.1-captcha0 

this will also install lua-gd ( aka liblua5.1-gd ) from the same repository

License

lua-captcha is released under MIT license