Home > php教程 > php手册 > body text

PHP图片验证码制作(中)

WBOY
Release: 2016-06-13 10:49:06
Original
1341 people have browsed it

随机生成数字,字母的代码:
 
//che.php
session_start();
for($i=0;$i  {
 $rand.=dechex(rand(1,15));
 }
 $_SESSION['check_num']=$rand;
$image=imagecreatetruecolor(50,30);
$bg=imagecolorallocate($im,0,0,0);//第一次用调色板的时候,背景颜色
$te=imagecolorallocate($im,255,255,255);
imagestring($image,6,rand(0,20),rand(0,2),$rand,$te);
ob_clean();//PHP网页中因为 要生成验证码而出现 图像"http://localhost/**.php"因其本身有错无法显示
header("Content-type:image/jpeg"); imagejpeg($image);
?>
 
给图片画出干扰线代码:
for($i=0;$i {
$cg=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));//产生随机的颜色
imageline($im,rand(10,40),0,rand(10,40),20,$cg);
}
给图片画出干扰点的代码:
for($i=0;$i {
imagesetpixel($im,rand(0,40),rand(0,20),$cg);
}
把文字写入图片代码:
 
$str=array('我','我','亲','亲');//存储显示的汉字
for($i=0;$i {
     $sss.=$str[rand(0,3)];//随机显示汉字
}

//$str=iconv("gb2312","utf-8",$str); //汉字编码转化,我的好像不需要
imagettftext($im,10,0,rand(5,60),rand(5,60),$te,"simhei.ttf",$sss);//
 
0:字体的倾斜度,“simhei.ttf”:字体样式,一般放在根目录下;

 

 

摘自 ms.元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!