GD::SecurityImage::Utils - generate captcha images and save to file
Example Usage:
use GD::SecurityImage::Utils; use Cwd; my $abs_captcha_table_file = cwd().'/t/captcha_table.txt'; my $abs_font = cwd().'/t/luxisr.ttf'; unlink $abs_captcha_table_file; # reset it # 1) CREATE A LIST OF IMAGES TO CREATE my $max = 20; # how many? my @abs_captchas; while( $max-- ){ push @abs_captchas, cwd()."/t/captcha_$max.png"; } # 2) GENERATE IMAGES AND SAVE CODES # save codes in a text file for lookup open( CAPTCHA_TABLE_FILE, '>>',$abs_captcha_table_file) or die($!); # for each in the list, make a image, and record the right code for my $abs_out ( @abs_captchas ){ unlink $abs_out; # just in case # create the captcha image and find out what the code is my $correct_code = write_captcha($abs_out,{font=>$abs_font}); # save it in the file for later lookups print CAPTCHA_TABLE_FILE "$correct_code=$abs_out\n"; -f $abs_out or die; # double check ? } close CAPTCHA_TABLE_FILE;
argument is absolute file path to write captcha image to, should be a png or jpg format optional argument is a hash ref with following options
width - number, pixels accross height - height, pixels up down, default is 50 ptsize - font point size, default is 32 lines rndmax font - abs path to font file, no default set bgcolor
returns correct code for image file
my $correct_code = write_captca($abs_out); my $correct_code = write_captca($abs_out, { font => '/abs/path/to.ttf' });
GD::SecurityImage
Leo Charre
To install GD::SecurityImage::Utils, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GD::SecurityImage::Utils
CPAN shell
perl -MCPAN -e shell install GD::SecurityImage::Utils
For more information on module installation, please visit the detailed CPAN module installation guide.