纯PERL 实现四位数字图片的生成

纯PERL 实现四位数字图片的生成

纯PERL 实现四位数字图片的生成
#==============================================================
# bmpnum usage: $img=bmpNum(1234); #用于生成四位验证码程序,做网页的一定知道这个东东了返回一个图片
#==============================================================
sub bmpNum{
my $verifynum=shift;
#BMP图片生成
local @n0 = ("3c","66","66","66","66","66","66","66","66","3c");
local @n1 = ("1c","0c","0c","0c","0c","0c","0c","0c","1c","0c");
local @n2 = ("7e","60","60","30","18","0c","06","06","66","3c");
local @n3 = ("3c","66","06","06","06","1c","06","06","66","3c");
local @n4 = ("1e","0c","7e","4c","2c","2c","1c","1c","0c","0c");
local @n5 = ("3c","66","06","06","06","7c","60","60","60","7e");
local @n6 = ("3c","66","66","66","66","7c","60","60","30","1c");
local @n7 = ("30","30","18","18","0c","0c","06","06","66","7e");
local @n8 = ("3c","66","66","66","66","3c","66","66","66","3c");
local @n9 = ("38","0c","06","06","3e","66","66","66","66","3c");

for (my $i = 0; $i < 10; $i++)
{
for (1 .. 6)
{
my $a1 = substr("012", int(myrand(3)), 1) . substr("012345", int(myrand(6)), 1);
my $a2 = substr("012345",int(myrand(6)),1) . substr("0123", int(myrand(4)), 1);
int(myrand(2)) eq 1 ? push(@{"n$i"}, $a1) : unshift(@{"n$i"},$a1);
int(myrand(2)) eq 0 ? push(@{"n$i"}, $a1) : unshift(@{"n$i"},$a2);
}
}

my @bitmap = ();

for (my $i = 0; $i < 20; $i++)
{
for (my $j = 0; $j < 4; $j++)
{
my $n = substr($verifynum, $j, 1);
my $bytes = ${"n$n"}[$i];
my $a = int(myrand(15));
$a eq 1 ? $bytes =~ s/9/8/g : $a eq 3 ? $bytes =~ s/c/e/g : $a eq 6 ? $bytes =~ s/3/b/g : $a eq 8 ? $bytes =~ s/8/9/g : $a eq 0 ? $bytes =~ s/e/f/g : 1;
push(@bitmap, $bytes);
}
}
for ($i = 0; $i < 8; $i++)
{
my $a = substr("012", int(myrand(3)), 1) . substr("012345", int(myrand(6)), 1);
unshift(@bitmap, $a);
push(@bitmap, $a);
}

my $image = '424d9e000000000000003e0000002800';
$image .= "00002000000018000000010001000000";
$image .= "00006000000000000000000000000000";
$image .= "00000000000000000000FFFFFF00";
$image .= join('', @bitmap);
$image = pack ('H*', $image);

return $image;
}
#===============================================================
###########################
##made by MR.WATER QQ:175 785 113 #
## 抄于雷傲论坛代码 #
###########################

好像不能用
好像不能用
报错
Name "main::n8" used only once: possible typo at ./digit_perl.pl line 21.
Name "main::n2" used only once: possible typo at ./digit_perl.pl line 15.
Name "main::n4" used only once: possible typo at ./digit_perl.pl line 17.
Name "main::n0" used only once: possible typo at ./digit_perl.pl line 13.
Name "main::n7" used only once: possible typo at ./digit_perl.pl line 20.
Name "main::n5" used only once: possible typo at ./digit_perl.pl line 18.
Name "main::n9" used only once: possible typo at ./digit_perl.pl line 22.
Name "main::n1" used only once: possible typo at ./digit_perl.pl line 14.
Name "main::n6" used only once: possible typo at ./digit_perl.pl line 19.
Name "main::n3" used only once: possible typo at ./digit_perl.pl line 16.
Undefined subroutine &main::myrand called at ./digit_perl.pl line 28.
大哥,报的错我看了下,只.
大哥,报的错我看了下,只要把所有的myrand改为rand就可以解决问题了,

至于Name "main::n6" used only once: possible typo at ./digit_perl.pl line 19.
这样的错误我不想去过问了,因为我只负责代码能用,呵呵
by MR.WATER
#=======================.
#==============================================================
# bmpnum usage: $img=bmpNum(1234); #用于生成四位验证码程序,做网页的一定知道这个东东了返回一个图片
#==============================================================
#use strict;

open my $file,">x.bmp";
print $file bmpNum(9874);
sub bmpNum{
my $verifynum=shift;
#BMP图片生成
my @n0 = ("3c","66","66","66","66","66","66","66","66","3c");
my @n1 = ("1c","0c","0c","0c","0c","0c","0c","0c","1c","0c");
my @n2 = ("7e","60","60","30","18","0c","06","06","66","3c");
my @n3 = ("3c","66","06","06","06","1c","06","06","66","3c");
my @n4 = ("1e","0c","7e","4c","2c","2c","1c","1c","0c","0c");
my @n5 = ("3c","66","06","06","06","7c","60","60","60","7e");
my @n6 = ("3c","66","66","66","66","7c","60","60","30","1c");
my @n7 = ("30","30","18","18","0c","0c","06","06","66","7e");
my @n8 = ("3c","66","66","66","66","3c","66","66","66","3c");
my @n9 = ("38","0c","06","06","3e","66","66","66","66","3c");

for (my $i = 0; $i < 10; $i++)
{
for (1 .. 6)
{
my $a1 = substr("012", int(rand(3)), 1) . substr("012345", int(rand(6)), 1);
my $a2 = substr("012345",int(rand(6)),1) . substr("0123", int(rand(4)), 1);
int(rand(2)) eq 1 ? push(@{"n$i"}, $a1) : unshift(@{"n$i"},$a1);
int(rand(2)) eq 0 ? push(@{"n$i"}, $a1) : unshift(@{"n$i"},$a2);
}
}

my @bitmap = ();

for (my $i = 0; $i < 20; $i++)
{
for (my $j = 0; $j < 4; $j++)
{
my $n = substr($verifynum, $j, 1);
my $bytes = ${"n$n"}[$i];
my $a = int(rand(15));
$a eq 1 ? $bytes =~ s/9/8/g : $a eq 3 ? $bytes =~ s/c/e/g : $a eq 6 ? $bytes =~ s/3/b/g : $a eq 8 ? $bytes =~ s/8/9/g : $a eq 0 ? $bytes =~ s/e/f/g : 1;
push(@bitmap, $bytes);
}
}
for (my $i = 0; $i < 8; $i++)
{
my $a = substr("012", int(rand(3)), 1) . substr("012345", int(rand(6)), 1);
unshift(@bitmap, $a);
push(@bitmap, $a);
}

my $image = '424d9e000000000000003e0000002800';
$image .= "00002000000018000000010001000000";
$image .= "00006000000000000000000000000000";
$image .= "00000000000000000000FFFFFF00";
$image .= join '', @bitmap ;
$image = pack ('H*', $image);

return $image;
}
#===============================================================
###########################
##made by MR.WATER QQ:175 785 113 #
## 抄于雷傲论坛代码 #
###########################
改的这个依然抱错.
不错




   

这个功能CPAN上不是有现成.
这个功能CPAN上不是有现成的模块的么。。
[quote]回复给 kylinhuang.
[quote]回复给 kylinhuang : 这个功能CPAN上不是有现成....[/quote]

[CCB]10[/CCB]什么模块?