编程笔记

php-验证码

11/27/2021 7:41:00 AM
0
//封装为函数调用
<?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);
?>

友情链接

Copyright @2021-2025 关于