GD库的函数
1,imagecreatetruecolor -----创建一个真彩色的图像
imagecreatetruecolor(int x_size,int y_size) //x表示宽,y表示高
2,imagecolorallocate 为一幅图像分配颜色(调色板)
imagecolorallocate(resource image,int red,int green,int blue)//red,green,blue----三原色
3,imagestring 绘图函数
iamgestring(resource image,font,int x,int y,内容,颜色);
4,输出函数
php的header是定义头的动作,php5中支持3中类型:
1,Content-type:xxxx/yyyy
2,Location:xxxx:yyyy/zzzz
3,Status:nnn xxxxxx
xxxx/yyyy表示内容文件的类型
如:image/gif
image/jpeg
image/png
例子:header("Content-type:image/jpeg")
GD库中有对应的image类型
imagejpeg(),imagegif(),imagepang()
5,imageline画线函数
iamgeline(resource image,int x1,int y1,int x2,int y2,int color);
image ---图片
x1 ---启始坐标
y1
x2 ---终点坐标
y2
6,imagesetpixel画点函数
imagesetpixel(resource image,int x,int y,int color)
7,imagettftext带字体的写入函数
imagettftext(resource image,float size,float angle,int x,int y,int color,string fontfile,string text)
8,php验证码插入中文的方法
iconv("gb2312","utf-8","字符串"); //首先要将文字转换成utf-8格式
9,随机函数
1,rand([int min,int max]) //rand(1,4) 生成1-4的数
2, dechex(十进制数) //转换为十六进制
做验证码的步骤:
生成随机数 -- 创建图片 -- 随机数写成图片 --保存在session中
输入验证码例子
gdchek.php
复制代码 代码如下:
<?php
/*
* 生成图片验证码
* and open the template in the editor.
*/
session_start();
for($i=0;$i<4;$i++){
$rand.=dechex(rand(1,15)); //生成4位数包含十六进制的随机数
}
$_SESSION[check_gd]=$rand;
$img=imagecreatetruecolor(100,30); //创建图片
$bg=imagecolorallocate($img,0,0,0); //第一次生成的是背景颜色
$fc=imagecolorallocate($img,255,255,255); //生成的字体颜色
//给图片画线
for($i=0;$i<3;$i++){
$te=imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255));
imageline($img,rand(0,15),0,100,30,$te);
}
//给图片画点
for($i=0;$i<200;$i++){
$te=imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($img,rand()%100,rand()%30,$te);
}
//首先要将文字转换成utf-8格式
//$str=iconv("gb2312","utf-8","呵呵呵");
//加入中文的验证
//smkai.ttf是一个字体文件,为了在别人的电脑中也能起到字体作用,把文件放到项目的根目录,可以下载,还有本机C:\WINDOWS\Fonts中有
imagettftext($img,11,10,20,20,$fc,"simkai.ttf","你好你好");
//把字符串写在图片中
//imagestring($img,rand(1,6),rand(3,70),rand(3,16),$rand,$fc);
//输出图片
header("Content-type:image/jpeg");
imagejpeg($img);
?>
login.php
复制代码 代码如下:
<?php
/*
*
*
*/
session_start();
if($_POST[sub]){
//判断验证码是否相同
if($_POST[gd_pic]==$_SESSION[check_gd]){
echo "验证成功!";
}else{
echo "验证码错误";
}
}
?>
<form action="login.php" method="POST">
用户名:<input type="text" name="user"/><br>
密码:<input type="password" name="pwd"/><br>
验证码:<imput type="text" name="gd_pic"/><img src="/UploadFiles/2021-04-02/gdchek.php"><imput type="submit" name="sub" value="submit"/>
</form>
1,imagecreatetruecolor -----创建一个真彩色的图像
imagecreatetruecolor(int x_size,int y_size) //x表示宽,y表示高
2,imagecolorallocate 为一幅图像分配颜色(调色板)
imagecolorallocate(resource image,int red,int green,int blue)//red,green,blue----三原色
3,imagestring 绘图函数
iamgestring(resource image,font,int x,int y,内容,颜色);
4,输出函数
php的header是定义头的动作,php5中支持3中类型:
1,Content-type:xxxx/yyyy
2,Location:xxxx:yyyy/zzzz
3,Status:nnn xxxxxx
xxxx/yyyy表示内容文件的类型
如:image/gif
image/jpeg
image/png
例子:header("Content-type:image/jpeg")
GD库中有对应的image类型
imagejpeg(),imagegif(),imagepang()
5,imageline画线函数
iamgeline(resource image,int x1,int y1,int x2,int y2,int color);
image ---图片
x1 ---启始坐标
y1
x2 ---终点坐标
y2
6,imagesetpixel画点函数
imagesetpixel(resource image,int x,int y,int color)
7,imagettftext带字体的写入函数
imagettftext(resource image,float size,float angle,int x,int y,int color,string fontfile,string text)
8,php验证码插入中文的方法
iconv("gb2312","utf-8","字符串"); //首先要将文字转换成utf-8格式
9,随机函数
1,rand([int min,int max]) //rand(1,4) 生成1-4的数
2, dechex(十进制数) //转换为十六进制
做验证码的步骤:
生成随机数 -- 创建图片 -- 随机数写成图片 --保存在session中
输入验证码例子
gdchek.php
复制代码 代码如下:
<?php
/*
* 生成图片验证码
* and open the template in the editor.
*/
session_start();
for($i=0;$i<4;$i++){
$rand.=dechex(rand(1,15)); //生成4位数包含十六进制的随机数
}
$_SESSION[check_gd]=$rand;
$img=imagecreatetruecolor(100,30); //创建图片
$bg=imagecolorallocate($img,0,0,0); //第一次生成的是背景颜色
$fc=imagecolorallocate($img,255,255,255); //生成的字体颜色
//给图片画线
for($i=0;$i<3;$i++){
$te=imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255));
imageline($img,rand(0,15),0,100,30,$te);
}
//给图片画点
for($i=0;$i<200;$i++){
$te=imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($img,rand()%100,rand()%30,$te);
}
//首先要将文字转换成utf-8格式
//$str=iconv("gb2312","utf-8","呵呵呵");
//加入中文的验证
//smkai.ttf是一个字体文件,为了在别人的电脑中也能起到字体作用,把文件放到项目的根目录,可以下载,还有本机C:\WINDOWS\Fonts中有
imagettftext($img,11,10,20,20,$fc,"simkai.ttf","你好你好");
//把字符串写在图片中
//imagestring($img,rand(1,6),rand(3,70),rand(3,16),$rand,$fc);
//输出图片
header("Content-type:image/jpeg");
imagejpeg($img);
?>
login.php
复制代码 代码如下:
<?php
/*
*
*
*/
session_start();
if($_POST[sub]){
//判断验证码是否相同
if($_POST[gd_pic]==$_SESSION[check_gd]){
echo "验证成功!";
}else{
echo "验证码错误";
}
}
?>
<form action="login.php" method="POST">
用户名:<input type="text" name="user"/><br>
密码:<input type="password" name="pwd"/><br>
验证码:<imput type="text" name="gd_pic"/><img src="/UploadFiles/2021-04-02/gdchek.php"><imput type="submit" name="sub" value="submit"/>
</form>
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 《幸福工厂》无限报错解决方法
- 交错战线原始交易所推荐角色一览
- 战锤40K星际战士2战术职业介绍|战术职业技能效果一览
- 战锤40K星际战士2突击职业介绍|突击职业技能效果一览
- [妙音金曲]群星《悲情咖啡屋》(黑胶)2CD[DTS-WAV]
- 阿兰·达瓦卓玛《A-Lan阿兰唯美歌姬》2CD[DTS-WAV]
- 【小提琴】陈立新《思乡曲》2004[FLAC+CUE]
- 《战地》新作明年初大规模测试!EA已内部测试一年
- 《GTAOL》PC版时隔多年更新反作弊!小助手宣布跑路
- EA称AI是其业务核心!能提高开发效率、节约成本
- 卫华.1990-太阳升【BMG】【WAV+CUE】
- 呼吸乐队.1992-THEBREATHING【深飞】【WAV+CUE】
- 李玟.2008-1994-2008豪华典藏精选2CD【SONY】【WAV+CUE】
- 《张学友 再现歌神的光辉岁月 梦想成真 2CD》[WAV/分轨][1.2GB]
- 《海来阿木 高音测试王》[WAV+CUE][500MB]