php-验证码

//封装为函数调用
<?php 
function show($fontsize){
    //创建画布资源
	$im=imagecreatetruecolor(200, 100);
    //准备颜料
	$gray=imagecolorallocate($im, 100, 100, 100);
	$black=imagecolorallocate($im,0, 0, 0);
    //画布背景
	imagefill($im, 0, 0, $gray);		
    //在画布上写字或画图
	$strarr=@array_merge(range(0,9),range(a,z),range(A,Z));
	shuffle($strarr);
	$str=join(array_slice($strarr,0,4));
	 $file="msyh.ttf";
	 imagettftext($im, $fontsize, 0, 50,50, $black, $file, $str);
    //输出
    header("content-type:image/png");
    imagepng($im);
    //释放资源
    imagedestroy($im);	
}
show(15);
?>

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注