<?php
/*
* Filename: authimg.php
* Author: haton
* Date: 2003-04-28
* @CopyRight 2006-12
*/
//生成验证码图片
Header("Content-type: image/png");
$str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$im = imagecreate(62,20);
$bgcolor = imagecolorallocate($im, 212,208,200);
imagefill($im,62,20,$c1);
$black = ImageColorAllocate($im, 0,0,0);
imagerectangle($im,0,0,61,19,$black);
$c1[0] = ImageColorAllocate($im, 19,31,113);
$c1[1] = ImageColorAllocate($im, 255,102,102);
$c1[1] = ImageColorAllocate($im, 222,108,39);
$c1[2] = ImageColorAllocate($im, 23,94,123);
$c1[3] = ImageColorAllocate($im, 0,0,0);
$c1[4] = imagecolorallocate($im, 141,56,56);
$p=0;
for($i=0;$i<200;$i++) //加入干扰象素
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, 2+rand()%56 , 2+rand()%16 , $randcolor);
}
for($i=0;$i<5;$i++)
{
//将四位整数验证码绘入图片
$authnum=rand(0,61);
$rstr=$rstr.substr($str,$authnum,1);
$p+=10;
imagechar($im,5,$p,2,substr($str,$authnum,1),$c1[rand(0,3)]);
}
ImagePNG($im);
ImageDestroy($im);
?>