在php中动态生成不同字体颜色的png格式验证图片

王朝php·作者佚名  2006-01-10
窄屏简体版  字體: |||超大  

<?

session_start();

//生成验证码图片

Header("Content-type: image/PNG");

$authnum=$_SESSION["authnum"];

srand((double)microtime()*1000000);

$len = strlen($authnum)*12+10;

$im = imagecreate($len,25);

$color[]= array ();

$color[1] = ImageColorAllocate($im, 0x00,0x00,0x00);

$color[2] = ImageColorAllocate($im, 0x00,0x00,0xff);

$color[3] = ImageColorAllocate($im, 0xff,0x33,0x00);

$color[4] = ImageColorAllocate($im, 0x00,0x00,0x99);

$color[5] = ImageColorAllocate($im, 0xff,0x00,0xff);

$color[6] = ImageColorAllocate($im, 0x99,0x66,0xff);

$color[7] = ImageColorAllocate($im, 0x00,0x99,0x99);

$color[8] = ImageColorAllocate($im, 0xff,0xff,0x00);

if($background)

{

$r = substr($background, 0, 2);

$g = substr($background, 2, 2);

$b = substr($background, 4, 2);

$bg = ImageColorAllocate($im, hexdec("0x".$r),hexdec("0x".$g),hexdec("0x".$b));

}

else

{

$bg = ImageColorAllocate($im, 0xcc,0xcc,0xff);

}

imagefill($im, 0, 0, $bg);

for($i=0,$x=5;$i<strlen($authnum);$i++)

{

imagestring($im, 5, $x, rand(2,8), $authnum[$i], $color[rand(1,8)]);

$x+=12;

}

for($i=0;$i<100;$i++) //加入干扰象素

{

$randcolor = ImageColorallocate($im,rand(100,255),rand(100,255),rand(100,255));

imagesetpixel($im, rand()%$len , rand()%30 , $randcolor);

}

ImagePNG($im);

ImageDestroy($im);

?>

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航