描述:用于生成验证码
<?php
function Vcode(){
/*
* 图像处理-验证码
*/
// 1、创建图像
//输出图像,谷歌,火狐会出现乱码,要进行说明,使用header
header('Content-type:image/jpeg');
//图片的大小
$width = 120;
$height = 40;
$img = imagecreatetruecolor($width, $height);
//图片颜色
$color1 = imagecolorallocate($img, rand(200, 255), rand(200, 255), rand(200, 255));
//像素颜色
$color2 = imagecolorallocate($img, rand(100, 200), rand(100, 200), rand(100, 200));
//字体颜色
$color3 = imagecolorallocate($img, rand(20, 50), rand(20, 50), rand(20, 50));
//$color3=imagecolorallocate($img,0,0,0);
//绘制像素点
for ($i = 0; $i < 50; $i++) {
imagesetpixel($img, rand(0, $width), rand(0, $height), $color2);
}
//填充 图像,位置,颜色
imagefill($img, 0, 0, $color1);
//绘制线条
imageline($img, rand(10, 30), rand(5, 30), rand(80, 100), rand(5, 30), $color2);
//绘制文字
$a = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'k', 'w', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$yzm = '';
for ($i = 0; $i < 5; $i++) {
$yzm .= $a[rand(0, count($a) - 1)];
}
imagettftext($img, 20, rand(-8, 8), 20, 30, $color3, 'font\QTTimeOutline.otf', $yzm);
//输出图像,所以先绘制像素点,最后将绘制好的图像输出
imagejpeg($img);
//释放资源
imagedestroy($img);
}
Vcode();
?>