php生成検証コード(回転と干渉線付き)


回転線と干渉線を持つ検証コード生成関数です.コードは次のとおりです.
<?php
	//            
	// string $text,       
	// int $linect,         
	// int $fontsize,    ,1 5
	// bool $rotate,    
	// array $textcol,    RGB ,array(R,G,B)
	// array $bgcol,   RGB ,array(R,G,B)
	function verifyCode($text, $linect=6, $fontsize=5, $rotate=array(-44,44), $textcol = array(255,0,0), $bgcol=array(255,255,255)){
		$len = strlen($text);
		$tximgw = imagefontwidth($fontsize);
		$tximgh = imagefontheight($fontsize);

		$imgof = $tximgw/2;
		$imgw = $len*($tximgw+$imgof);
		$imgh = $tximgh;
		
		$img = imagecreate($imgw, $imgh);

		imagefill($img, 0,0, imagecolorallocate($img, $bgcol[0], $bgcol[1], $bgcol[2]));
		
		//     
		for($i=0; $i<$len; ++$i){
			$char = $text[$i];
			$tximg = imagecreate($tximgw, $tximgh);
			$txbgcol = imagecolorallocate($tximg, $bgcol[0], $bgcol[1], $bgcol[2]);
			$txcol = imagecolorallocate($tximg, $textcol[0], $textcol[1], $textcol[2]);
			imagestring($tximg, $fontsize, 0, 0, $char, $txcol);
			$ag = $rotate?rand($rotate[0],$rotate[1]):0;
			
			//         
			$oimg = imagerotate($tximg, $ag, $txbgcol);
			imagecopy($img, $oimg, $i*($tximgw+$imgof), 0 , 0 , 0 , imagesx($oimg) , imagesy($oimg));
			
			//            
			imagedestroy($tximg);
			imagedestroy($oimg);
		}
		
		//        
		for($i=0; $i<$linect; ++$i){
			$x = rand(0, $imgw);
			$y = rand(0, $imgh);
			$x1 = rand(0, $imgw);
			$y1 = rand(0, $imgh);
			imageline ($img, $x, $y, $x1, $y1, imagecolorallocate($img, rand(0,255), rand(0,255), rand(0,255)));
		}
		return $img;
	}
	//   
	$text = 'HelloWorld';
	//      5     ,   5,     [-30,30]     
	$img = verifyCode($text, 5, 5, array(-30, 30));
	//        png  
	header("Content-type: image/png");
	//   
	imagepng($img);
	//     
	imagedestroy($img);
?>

効果は図のようになります.