PHP学习笔记(5)GD库画验证码
2016-11-09 15:05
417 查看
1 <?php 2 header("content-type:image/png"); 3 $width = 500; 4 $height = 500; 5 $img = imagecreatetruecolor($width, $height); 6 $string = "hello"; 7 //7种颜色,存入数组 8 $red = imagecolorallocate($img, 255, 0, 0); 9 $white = imagecolorallocate($img, 255, 255, 255); 10 $green = imagecolorallocate($img, 0, 255, 0); 11 $blue = imagecolorallocate($img, 0, 0, 255); 12 $aaa = imagecolorallocate($img, 255, 255, 0); 13 $bbb = imagecolorallocate($img, 0, 255, 255); 14 $ccc = imagecolorallocate($img, 255, 0, 255); 15 $colors = array($white,$red,$green,$blue,$aaa,$bbb,$ccc); 16 //画点 17 for ($i=0; $i < 1000; $i++) { 18 imagesetpixel($img, mt_rand(0,$width), mt_rand(0,$height), $colors[mt_rand(0,6)]); 19 } 20 //划线 21 for ($i=0; $i < 200; $i++) { 22 imageline($img, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $colors[mt_rand(0,6)]); 23 } 24 //生成4位验证码 25 $a1 = range(0, 9); 26 $a2 = range(a, z); 27 $a3 = range(A, Z); 28 $a4 = array_merge($a1,$a2,$a3); 29 $num = 4; 30 $fontsize = 60; 31 for ($i=0; $i < 4; $i++) { 32 imagettftext($img, $fontsize, mt_rand(-45,45), $width/$num*$i+$fontsize, $height/2, $colors[mt_rand(0,6)], "Fonts/msyh.ttf", $a4[mt_rand(0,61)]); 33 } 34 35 imagepng($img); 36 ?>
------------------------------------------------------------------------------- -----------------------------------------------------------------------------
下面的小一点:
1 <?php 2 header("content-type:image/png"); 3 $width = 110; 4 $height = 40; 5 $img = imagecreatetruecolor($width, $height); 6 $string = "hello"; 7 //7种颜色,存入数组 8 $red = imagecolorallocate($img, 255, 0, 0); 9 $white = imagecolorallocate($img, 255, 255, 255); 10 $green = imagecolorallocate($img, 0, 255, 0); 11 $blue = imagecolorallocate($img, 0, 0, 255); 12 $aaa = imagecolorallocate($img, 255, 255, 0); 13 $bbb = imagecolorallocate($img, 0, 255, 255); 14 $ccc = imagecolorallocate($img, 255, 0, 255); 15 $colors = array($white,$red,$green,$blue,$aaa,$bbb,$ccc); 16 //画点 17 for ($i=0; $i < 10; $i++) { 18 imagesetpixel($img, mt_rand(0,$width), mt_rand(0,$height), $colors[mt_rand(0,6)]); 19 } 20 //划线 21 for ($i=0; $i < 4; $i++) { 22 imageline($img, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $colors[mt_rand(0,6)]); 23 } 24 //生成4位验证码 25 $a1 = range(0, 9); 26 $a2 = range(a, z); 27 $a3 = range(A, Z); 28 $a4 = array_merge($a1,$a2,$a3); 29 $num = 4; 30 $fontsize = 20; 31 for ($i=0; $i < 4; $i++) { 32 imagettftext($img, $fontsize, mt_rand(-45,45), $width/$num*$i+5, 30, $colors[mt_rand(0,6)], "Fonts/msyh.ttf", $a4[mt_rand(0,61)]); 33 } 34 imagepng($img); 35 ?>
相关文章推荐
- PHP学习笔记之使用GD库制作验证码(一)
- php学习笔记:利用gd库生成图片,并实现随机验证码
- php笔记之GD库图片创建/简单验证码
- PHP学习笔记-GD库与Jpgraph的使用
- PHP学习笔记5-PHP-AJAX请求、文件上传、验证码
- PHP学习笔记-----GD库
- 我的php学习笔记(三十一)PHP5中图片验证码的制作(下)
- php学习的笔记。包括ubuntu16.04不显示php代码的验证码(windeow下正常)等等,实时更新
- PHP学习笔记(8)验证码使用session对比
- PHP学习笔记5-PHP-AJAX请求、文件上传、验证码
- PHP学习笔记09——GD生成验证码实例
- php笔记之GD库图片创建/简单验证码
- PHP学习笔记(7)验证码优化
- php学习笔记:验证码
- PHP学习笔记-GD库作图
- PHP学习笔记:利用gd库给图片打图片水印
- [学习笔记]php验证码
- PHP学习笔记(3)GD库画图
- PHP学习笔记(6)js点击刷新验证码
- PHP开发学习笔记之生成验证码