PHP的GD库学习2:一个简单的验证码图片
2009-10-06 23:36
519 查看
使用两个函数增加验证码图片复杂程度,加干扰线和噪点。
1.imageline 与 imagesetpixel 函数
imageline 画线函数
imageline ( resource image, int x1, int y1, int x2, int y2, int color )
imagesetpixel 画点函数
imagesetpixel ( resource image, int x, int y, int color )
2.imagettftext函数调用字体写入文字
imagettftext 带字体的写入函数
imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text )
一个做好的测试程序
1.imageline 与 imagesetpixel 函数
imageline 画线函数
imageline ( resource image, int x1, int y1, int x2, int y2, int color )
imagesetpixel 画点函数
imagesetpixel ( resource image, int x, int y, int color )
2.imagettftext函数调用字体写入文字
imagettftext 带字体的写入函数
imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text )
一个做好的测试程序
<?php //生成四位随机数 for ($i = 0; $i < 4; $i++) { $rand .= dechex(rand(1, 15)); } //生成随机字体 $randfont = rand(1, 6); //生成随机x坐标 $randx = rand(2, 70); //生成随机y坐标 $randy = rand(2, 15); //创建100x30大小的图片 $im = imagecreatetruecolor(100, 30); //设置图片背景颜色为RGB 0,0,0 $bg = imagecolorallocate($im, 0, 0, 0); //获得RGB 255,255,255 的颜色编码 $color = imagecolorallocate($im, 255, 255, 255); //添加干扰线 for ($i = 0; $i < 5; $i++) { $x1 = rand(0, 100); $y1 = 0; $x2 = rand(0, 100); $y2 = 30; $linecolor = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255)); imageline($im,$x1,$y1,$x2,$y2,$linecolor); } //添加噪点 for ($i = 0; $i < 200; $i++) { $x = rand(0, 100); $y = rand(0, 30); $pixcolor = imagecolorallocate($im, rand(0, 255), rand(0, 255), rand(0, 255)); imagesetpixel($im, $x, $y, $pixcolor); } //更改文字编码 $string = iconv("gbk", "UTF-8", "新年好"); //在图片中写入文字 imagettftext($im, 12, -2, 2, 15, $color, 'simyou.ttf', $string); //在图片中写入随机数 //imagestring($im, $randfont, $randx, $randy, $rand, $color); //设置内容格式为images/jpeg header("Content-Type: image/jpeg"); //输出jpeg图片 imagejpeg($im); ?>
相关文章推荐
- PHP的GD库学习1:一个简单的随机数图片
- php笔记之GD库图片创建/简单验证码
- php学习笔记:利用gd库生成图片,并实现随机验证码
- PHP生成一个简单的验证码图片
- php笔记之GD库图片创建/简单验证码
- php笔记之GD库图片创建/简单验证码
- 一个简单的PHP验证码实现代码
- php学习,一个简单的Calendar(2) 一个简单的活动页面
- 一个简单安全的PHP验证码类、PHP验证码
- 一个简单的PHP验证码和验证方法。
- PHP学习笔记(5)GD库画验证码
- 我的php学习笔记(三十一)PHP5中图片验证码的制作(下)
- 【学习点滴-php】用GD库做个简单的进度条
- 用javase写一个简单的生成验证码图片的程序(verification code)
- PHP用GD库绘制图片,制作验证码浏览器不能输出
- sql server 关于表中只增标识问题 C# 实现自动化打开和关闭可执行文件(或 关闭停止与系统交互的可执行文件) ajaxfileupload插件上传图片功能,用MVC和aspx做后台各写了一个案例 将小写阿拉伯数字转换成大写的汉字, C# WinForm 中英文实现, 国际化实现的简单方法 ASP.NET Core 2 学习笔记(六)ASP.NET Core 2 学习笔记(三)
- 分享一个php验证码程序 简单 实用
- PHP 用session与gd库实现简单验证码生成与验证的类
- 一个简单的php图形验证码生成程序
- 一个最简单的php上传图片示例