PHP 生成图片

1.先确认是否有GD库

echo phpinfo();

复制代码
// 创建一个真彩色图像
$image = imagecreatetruecolor(120, 50);

// 分配颜色
$bgColor = imagecolorallocate($image, 255, 255, 255); // 白色背景
$textColor = imagecolorallocate($image, 230, 230, 230); // 黑色文字

// 填充背景
imagefill($image, 0, 0, $bgColor);

// 设置文字
$text = '你好';

// 字体文件路径,确保你有这个字体文件
$fontPath = $_SERVER['DOCUMENT_ROOT'] . '/static/ttfs/1.ttf';

// 将文字写入图像
imagettftext($image, 10, 15, 5, 45, $textColor, $fontPath, $text);

// 输出图像到浏览器
header('Content-Type: image/png');
imagepng($image,$_SERVER['DOCUMENT_ROOT'] . '/img/sign/' . $user['id'] . '.png');

// 释放与image相关联的内存
imagedestroy($image);
相关推荐
Lhappy嘻嘻17 小时前
Java IO|File 文件操作 + 字节流 / 字符流完整笔记 + 递归删除文件实战
java·笔记·php
2601_9637713720 小时前
How to Scale Your WordPress Store Traffic in 2026
前端·php·plugin
右耳朵猫AI1 天前
PHP周刊2026W28 | 安全更新、Laravel 13.18、Twig 3.28
开发语言·php·laravel
罗政1 天前
PDF 批量合并工具:本地 AI 自动排序、识别正文日期与合同编号
数据库·pdf·php
糖果店的幽灵1 天前
安全测试从入门到精通_网络基础与HTTPS
网络·https·php
2601_963771371 天前
WordPress SEO Guide: Boost Rankings Without Technical Jargon
前端·php
日取其半万世不竭1 天前
CS2 服务器搜不到?GSLT、端口和启动参数逐项检查
运维·服务器·php
360智汇云1 天前
一次Redis超时引发的“冤案“
数据库·redis·php
ljs6482739511 天前
Linux 网络常用命令与端口基础详解
linux·网络·php
m0_738120722 天前
PHP代码审计基础——超全局变量(三)
开发语言·安全·网络安全·php