自己写了个简单的php验证码:
<?php
$img=ImageCreate(200,50);
$background_color=ImageColorAllocate($img,255,255,255);
$gray=ImageColorAllocate($img,255,0,0);
//画点
for($i=0;$i<100;$i++)
{
$pointcolor=ImageColorAllocate($img,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
ImageSetPixel($img,mt_rand(50,149),mt_rand(10,39),$pointcolor);
}
//划线
for($k=0;$k<2;$k++)
{
$linecolor=ImageColorAllocate($img,mt_rand(0,255),255,mt_rand(0,255));
$sy=mt_rand(11,39);
$ey=mt_rand(11,39);
ImageLine($img,50,$sy,150,$ey,$linecolor);
}
//字符
$pattern='1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
for($j=0;$j<4;$j++)
{
$fontcolor=ImageColorAllocate($img,0,0,0);
$x=mt_rand(60,140);
$y=mt_rand(15,25);
$key=$pattern[mt_rand(0,62)];
ImageString($img,5,$x,$y,$key,$fontcolor);
}
//画矩形
ImageRectangle($img,50,10,150,40,$gray);
header('Content-Type:image/png');
//生成图像
ImagePNG($img);
ImageDestroy($img);
?>