package tapi; # test api use strict; use vars qw[$VERSION %data %info_text $GD $MAGICK $PROBLEM]; $VERSION = '0.40'; $GD = defined($GD::VERSION) ? $GD::VERSION : 0; $MAGICK = defined($Image::Magick::VERSION) ? $Image::Magick::VERSION : '0.0.0'; $PROBLEM = ($GD && $GD < 2.07) ? 1 : 0; sub the_info_text { 'GD::SecurityImage' } sub GD::SecurityImage::__cit { # __check_info_text my $self = shift; if (%info_text) { $self->info_text(%info_text); } $self; } sub styles { qw( default rect box circle ellipse ec ) } sub options { my $class = shift; %data = @_ if @_; if ( $data{info_text} ) { %info_text = %{ delete $data{info_text} }; } %data; } sub _can { my $self = shift; my $name = shift || ''; if ( $PROBLEM && ($name eq 'ellipse' or $name eq 'ec') ) { return 'circle'; } return $name; } sub clear { %data = (); %info_text = () } sub set { my $class = shift; unless (scalar @_ %2) { if (@_) { my %o = @_; foreach(keys %o) { next if $_ eq 'thickness' && $PROBLEM; $data{$_} = $o{$_}; } } } $class } sub random { { ec => 'EC0123', ellipse => 'ELLIPS', circle => 'CIRCLE', box => 'BOX012', rect => 'RECT01', default => 'DFAULT', } } sub save { my $class = shift; my ($image, $mime, $random, $style, $ID, $counter) = @_; my $name = sprintf "%s_%02d_%s.%s", $ID, $counter, $style, $mime; local *SI; open SI, ">$name" or die "Error writing the image '$name' to disk: $!"; binmode SI; print SI $image; close SI; print "[OK] $name\n"; return 'SUCCESS'; } package gd_normal; sub ec { GD::SecurityImage ->new(lines => 5, bgcolor => [0,0,0], tapi->options) ->random(tapi->random->{ec}) ->create(normal => 'ec', [84, 207, 112], [0,0,0]) ->particle(100)->__cit } sub ellipse { GD::SecurityImage ->new(lines => 10, bgcolor => [208, 202, 206], tapi->options) ->random(tapi->random->{ellipse}) ->create(normal => tapi->_can('ellipse'), [31,219,180], [231,219,180]) ->particle(100)->__cit } sub circle { GD::SecurityImage ->new(lines => 5, bgcolor => [210, 215, 196], tapi->options) ->random(tapi->random->{circle}) ->create(normal => 'circle', [63, 143, 167], [90, 195, 176]) ->particle(250, 2)->__cit } sub box { GD::SecurityImage ->new(lines => 5, tapi->options) ->random(tapi->random->{box}) ->create(normal => 'box', [63, 143, 167], [226, 223, 169]) ->particle(150, 4)->__cit } sub rect { GD::SecurityImage ->new(lines => 10, tapi->options) ->random(tapi->random->{rect}) ->create(normal => 'rect', [63, 143, 167], [226, 223, 169]) ->particle(100)->__cit } sub default { GD::SecurityImage ->new(lines => 10, tapi->options, send_ctobg => 0) ->random(tapi->random->{default}) ->create(normal => 'default', [68,150,125], [255,0,0]) ->particle(500)->__cit } package gd_ttf; sub ec { GD::SecurityImage ->new(lines => 16, bgcolor => [0,0,0], tapi->set(thickness => 1)->options) ->random(tapi->random->{ec}) ->create(ttf => 'ec', [84, 207, 112], [0,0,0]) ->particle(1000)->__cit } sub ellipse { GD::SecurityImage ->new(lines => 15, bgcolor => [208, 202, 206], tapi->set(thickness => 2)->options) ->random(tapi->random->{ellipse}) ->create(ttf => tapi->_can('ellipse'), [184,20,180], [184,20,180]) ->particle(2000)->__cit } sub circle { GD::SecurityImage ->new(lines => 50, bgcolor => [210, 215, 196],tapi->set(thickness => 1)->options) ->random(tapi->random->{circle}) ->create(ttf => 'circle', [63, 143, 167], [210, 215, 196]) ->particle(3500)->__cit } sub box { GD::SecurityImage ->new(lines => 6, tapi->set(thickness => 1)->options, frame => 0) ->random(tapi->random->{box}) ->create(ttf => 'box', [245,240,220], [115, 115, 115]) ->particle(3000, 2)->__cit } sub rect { GD::SecurityImage ->new(lines => 30, tapi->set(thickness => 1)->options) ->random(tapi->random->{rect}) ->create(ttf => 'rect', [63, 143, 167], [226, 223, 169]) ->particle(2000)->__cit } sub default { GD::SecurityImage ->new(lines => 10, tapi->set(thickness => 2)->options) ->random(tapi->random->{default}) ->create(ttf => 'default', [68,150,125], [255,0,0]) ->particle(5000)->__cit } package gd_normal_scramble; use base qw(gd_normal); package gd_ttf_scramble; use base qw(gd_ttf); package gd_ttf_scramble_fixed; use base qw(gd_ttf); package gd_normal_info_text; use base qw(gd_normal); package gd_ttf_info_text; use base qw(gd_ttf); package gd_normal_scramble_info_text; use base qw(gd_normal); package gd_ttf_scramble_info_text; use base qw(gd_ttf); package gd_ttf_scramble_fixed_info_text; use base qw(gd_ttf); package magick; use base qw(gd_ttf); package magick_scramble; use base qw(gd_ttf); package magick_scramble_fixed; use base qw(gd_ttf); package magick_info_text; use base qw(gd_ttf); package magick_scramble_info_text; use base qw(gd_ttf); package magick_scramble_fixed_info_text; use base qw(gd_ttf); 1; __END__