<?php
// 创建一个空白图像并填充颜色
$im = imagecreatetruecolor(100, 100);
$white = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $white);
// 创建一个红色的矩形
$red = imagecolorallocate($im, 255, 0, 0);
imagefilledrectangle($im, 40, 40, 60, 60, $red);
// 输出图像到浏览器
header('Content-Type: image/png');
imagepng($im);
// 释放内存
imagedestroy($im);
?>
imagecreatetruecolor(100, 100)
创建一个 100x100 像素的空白图像。imagecolorallocate($im, 255, 255, 255)
分配白色(RGB: 255, 255, 255)给图像,并使用 imagefill
将整个图像填充为白色。imagefilledrectangle($im, 40, 40, 60, 60, $red)
在图像中绘制一个红色的矩形,位置从 (40, 40) 到 (60, 60)。header('Content-Type: image/png')
设置响应头为 PNG 图像格式,imagepng($im)
将图像输出到浏览器。imagedestroy($im)
销毁图像资源,释放内存。这个示例展示了如何使用 PHP 的 GD 库创建和操作图像。
上一篇:php 图片压缩
下一篇:php parse_str
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站