| 1 | package PEF::Front::SecureCaptcha; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use GD::SecurityImage; | ||
| 6 | |||
| 7 | sub generate_image { | ||
| 8 | my %args = @_; | ||
| 9 | my $pts = int ($args{height} / 2.5 + 0.5); | ||
| 10 | my $image = GD::SecurityImage->new( | ||
| 11 | rndmax => 1, | ||
| 12 | ptsize => $pts, | ||
| 13 | angle => "0E0", | ||
| 14 | scramble => 1, | ||
| 15 | lines => int ($args{size} / 1.5 + 0.5), | ||
| 16 | width => $args{width} * $args{size}, | ||
| 17 | height => $args{height}, | ||
| 18 | font => $args{font} | ||
| 19 | ); | ||
| 20 | $image->random($args{str}); | ||
| 21 | my $method = $args{font} =~ /\.ttf$/i ? 'ttf' : 'normal'; | ||
| 22 | $image->create($method => "ec")->particle($args{width} * $args{size}, 2); | ||
| 23 | my ($image_data, $mime_type, $random_number) = $image->out(force => "jpeg"); | ||
| 24 | open (my $oi, ">", "$args{out_folder}$args{code}.jpg") or die $!; | ||
| 25 | binmode $oi; | ||
| 26 | syswrite $oi, $image_data; | ||
| 27 | close $oi; | ||
| 28 | } | ||
| 29 | |||
| 30 | 1; |