php生成图片验证码

2010-3-6 杜世伟 Php

<?php
$string = "012efghnopq67ijklm89abcdr345stuvw34VJKL56xyz012789ABCDOPQRS678TUMN34WXYZ12EFGHI590";
for($i=1;$i<5;$i++){
$j = rand(0,81);
$rand.=substr($string,$j,1);
}
$im = imagecreatetruecolor(50,21);

$gdcolor = imagecolorallocate($im,205,205,205);

$red=imagecolorallocate($im,255,0,0);
$blue = imagecolorallocate($im,0,0,255);
$green = imagecolorallocate($im,0,255,0);
$randcolor = imagecolorallocate($im,rand(100,255),rand(100,255),rand(100,255));

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

//imagestring($im,12,10,2,$rand,$red);

for($i=0;$i<300;$i++){
imagesetpixel($im,rand(0,50),rand(0,20),$randcolor);
}

imagestring($im,rand(5,9),rand(0,12),rand(0,5),$rand,$red);
//imageline($im,0,0,60,10,$green);
//imageline($im,0,20,50,5,$blue);
session_start();
$_SESSION['image']=strtolower($rand);


header("content_type: image/jpeg");
imagejpeg($im);
// imagedestroy($im);
?>

Powered by emlog 沪ICP备2023034538号-1