php5中图片验证码制作
imagecreateturecolor(int x_size,int y_size)新建一个真彩色图像
imagecolorallocate(rescource image,int red,int green,int blue)
为一幅图片给分配颜色
imagestring(resource image,font,int x,int y,内容,颜色)
1.rand(int min ,int max)随机函数
dechex()十进制转换为十六进制
定义头部的动作
header(content-type:xxxx/yyyy) 文件的类型
location:xxx:yyy/zzz
status nnn xxxxx
GD库中有对应的image类型
imagejpeg()
imagegif()
imagepng()
imageline划线函数
imageline(resource image,int x1,int y1,int x2,int y2,int color)
imagesetpixel(rescource image ,int x,int y,int color)画点函数
imagettftext函数调用字体写入文字
imagettftext(recource image,float size,float angle,int x,int y,int color,string fontfile,string text)
php验证码插入中文的方法
iconv(“gb2312”,“utf-8”,“新年快乐”);
<?php
session_start();
for($i=0;$i<4;$i++)
{
$rand.=dechex(rand(1,15));
}
$_SESSION['check_pic']=$rand;
$im=imagecreatetruecolor(100,30);
$bg=imagecolorallocate($im,0,0,0);
$te=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
for($j=0;$j<3;$j++)
{
imageline($im,rand(0,100),0,100,30,$te);
}
for($k=0;$k<200;$k++)
{
imagesetpixel($im,rand()%100,rand()%30,$te);
}
$str=iconv("gbk","utf-8","新年快乐");
//$str="新年快乐";
imagettftext($im ,12,0,20,20,$te,'msyh.ttf',$str);
//imagestring($im,rand(4,6),rand(3,70),rand(0,16),$rand,$te);
header("content-type: image/jpeg");//header之前不能有任何输出
imagejpeg($im);
?>
本文出自 “php学习” 博客,谢绝转载!