大体思路:

代码部分:

 <?php
//1.创建画布
$img = imagecreatetruecolor(100,30);
//2.设置颜色 值越小,颜色越深
$color1 = imagecolorallocate($img,rand(100,255),rand(150,255),rand(170,255));
$color2 = imagecolorallocate($img,rand(0,100),rand(0,100),rand(0,100));
//3.填充矩形
imagefilledrectangle($img,0,0,100,30,$color1);
//4.数组的合并、调换、输出键值,并字符转换
$str = implode('',array_rand(array_flip(array_merge(range('a','z'),range('A','Z'))),4));
//5.填入文本
for($i = 0;$i < 4;$i++){
imagettftext($img,14,0,rand($i*100/4,($i+1)*(100/4)-10),rand(12,30),$color2,'./simfang.ttf',$str{$i});
}
//6.干扰元素-->点
for($i = 0;$i < 50;$i++){
imagesetpixel($img,rand(0,100),rand(0,30),$color2);
}
//7.输出头像
header('Content-type:image/png');
imagepng($img);
//8.释放资源
imagedestroy($img);
?>

【代码总结】GD库中简单的验证码的更多相关文章

  1. 【代码学习】GD库中简单的验证码

    大体思路: 代码部分: <?php //1.创建画布 $img = imagecreatetruecolor(100,30); //2.设置颜色 值越小,颜色越深 $color1 = image ...

  2. php中GD库的简单使用

    在php中需要图像处理的地方GD库会发挥重要的作用,php可以创建并处理包括GIF,PNG,JPEG,WBMP以及XPM在内的多种图像格式,简单的举几个例子: 1.用GD库会创建一块空白图片,然后绘制 ...

  3. php中运用GD库实现简单验证码

    昨天学习了运用php的GD库进行验证码的实现. 首先可以用phpinfo()函数看一下GD库有没有安装,我用的wampserver是自动给安装的. 主要的步骤是: 1.生成验证码图片 2.随机生成字符 ...

  4. PHP 用session与gd库实现简单验证码生成与验证的类

    验证码是为了防止机器灌水给网站带来污染以及增加服务器负担而出现的.目前大大小小的网站都有验证码.今天自己实现了一个简单的验证码类.说简单是因为没有加一些干扰的弧线等等,只是将文字旋转了一下.当然,因为 ...

  5. PHP利用GD库绘图和生成验证码图片

    首先得确定php.ini设置有没有打开GD扩展功能,測试例如以下 print_r(gd_info()); 假设有打印出内容例如以下,则说明GD功能有打开: Array ( [GD Version] = ...

  6. 【代码学习】GD库中图片缩印

    bool imagecopyresampled ( resource $dst_image, resource $src_image, int $dst_x, int $dst_y, int $src ...

  7. 【代码学习】GD库中添加图片水印

    函数 getimagesize() bool imagecopymerge( resource dst_im, resource src_im, int dst_x, int dst_y, int s ...

  8. 【代码总结】GD库中图片缩印

    bool imagecopyresampled ( resource $dst_image, resource $src_image, int $dst_x, int $dst_y, int $src ...

  9. 【代码总结】GD库中添加图片水印

    函数 getimagesize() bool imagecopymerge( resource dst_im, resource src_im, int dst_x, int dst_y, int s ...

随机推荐

  1. 「题解」「CF1019B」The hat

    目录 题目 背景 程序输出 交互程序输入 题解 程序 题目 背景 这是一道交互题. 一共有 \(n\) 个人做成一圈,他们的编号从 \(1\) 到 \(n\). 现在每个人的手里面都有一个数字 \(a ...

  2. Codeforces Round #598 (Div. 3) B Minimize the Permutation

    B. Minimize the Permutation You are given a permutation of length nn. Recall that the permutation is ...

  3. 常用统计分析python包开源学习代码 numpy pandas matplotlib

    常用统计分析python包开源学习代码 numpy pandas matplotlib 待办 https://github.com/zmzhouXJTU/Python-Data-Analysis

  4. js获取当前时间:yyyy-MM-dd HH:MM:SS

    var nowDate = new Date();var year = nowDate.getFullYear(); < ? ; ? " + nowDate.getDate() : n ...

  5. mvn + testng + allure 生成自动化测试报告

    最近学了个新东西,使用java的testng测试框架做自动化测试.并且声称自动化报告. (1)创建maven工程 File-New-Other (2)创建testng类 当前import org.te ...

  6. js数组和对象

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. THINKPHP 模板上传图片--后台接收图片

    模板 {extend name="public/base" /} {block name="body"} <div class="row&quo ...

  8. mysql 随笔

    (select GROUP_CONCAT(car_brand_name separator ',') carBrandName,supplier_id from ycej_supplier_carbr ...

  9. docker 报错 docker: Error response from daemon: driver failed....iptables failed:

    现象: [root@localhost test]# docker run --name postgres1 -e POSTGRES_PASSWORD=password -p : -d postgre ...

  10. Python socket day4

    TCP(较UDP麻烦但安全) 服务器和客户端区分的很明白 TCP客户端比起UDP多个连接服务器 TCP服务端 socket创建一个套接字 一定要绑定IP和端口,就跟110一样,是固定的让人随时能知道 ...