惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
J
Java Code Geeks
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Docker
腾讯CDC
The GitHub Blog
The GitHub Blog
大猫的无限游戏
大猫的无限游戏
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
Vercel News
Vercel News
P
Proofpoint News Feed
雷峰网
雷峰网
博客园_首页
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
爱范儿
爱范儿
V
V2EX
F
Fortinet All Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
MyScale Blog
MyScale Blog
S
SegmentFault 最新的问题

博客园 - Don

在Chrome中调试Android微信浏览器中的网页,不出现供选择页面的怎么办?(chrome://inspect/#devices) 使用Crontab集合sh脚本自动删除过期的Confluence Docker容器中的备份文件 解决命令行提示“cannot create temp file for here-document: No space left on device”但磁盘使用率并未满的问题 SSH登录后提示LC_ALL: cannot change locale (en_US.UTF8) 的解决办法 解决git操作一直要求输入用户名和密码的问题 CentOS如何增加虚拟内存 RabbitMQ集群脑裂故障处理 zookeeper日志定时清理 Alibaba Centos ECS 安全更新记录 AWS EC2配置CloudWatch 记录AWS Linux2 的yum安全更新步骤 记录Docker系统盘空间占用过大的解决方法 AWS EC2 EBS数据盘挂载与相关日常维护操作 AWS Amazon Linux2 安装Docker和Docker Compose [转]提升 Docker Desktop For macOS 磁盘使用率 AndroidGetAPKInfo --- 检查包名(packageName)、版本(versionName\versionCode)、应用签名(Signature)等信息 - Don OpenSSL命令—pkcs12 Linux下User与Group的常用操作命令解析 Docker搭建openvpn - Don
Docker PHP中安装gd扩展并生成图形验证码
Don · 2023-11-15 · via 博客园 - Don

在容器中执行:

apt install libjpeg62-turbo-dev libfreetype6-dev -y

docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg

docker-php-ext-install gd

可运行:php --ri gd 查看安装结果,重启docker容器。

图形验证码示例代码:

<?php
session_start();
function random($len) {
    $srcstr = "123456789ABCDEFGHJKLNPQRSTUVXYZ";
    $strs = "";
    for ($i = 0; $i < $len; $i++) {
        $strs .= $srcstr[mt_rand(0,30)];
    }
    return $strs;
}
 
//随机生成的字符串
$str = random(5); 
 
//验证码图片的宽度
$width  = 80;      
 
//验证码图片的高度
$height = 40;     
 
//声明需要创建的图层的图片格式
@ header("Content-Type:image/png");
 
//创建一个图层
$im = imagecreate($width, $height);
 
//背景色
$back = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
 
//模糊点颜色
$pix  = imagecolorallocate($im, 100, 207, 95);
 
//字体色
$color = imagecolorallocate($im, 100, 207, 2);

//边框颜色
$col = imagecolorallocate($im, 100, 164, 26);

//字体
putenv('GDFONTPATH=' . realpath('.'));//解决linux下GD库版本低于2.0.18不能显示的问题
$font = 'arial.ttf';
 
//绘模糊作用的点
mt_srand();
for ($i = 0; $i < 800; $i++) {
    imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $pix);
}
 
//输出字符
imagettftext($im, 16, 0, 5, 28, $color, $font, $str);

//输出矩形
imagerectangle($im, 0, 0, $width -1, $height -1, $col);
 
//输出图片
imagepng($im);
 
imagedestroy($im);
 
$str = md5(strtolower($str));
 
//选择 Session
$_SESSION["verification"] = $str;
?>