<?php
// 创建一个图像资源
$im = imagecreatetruecolor(100, 100);
// 分配颜色
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// 填充背景为白色
imagefill($im, 0, 0, $white);
// 画一个黑色的矩形
imagerectangle($im, 10, 10, 90, 90, $black);
// 将图像输出为 PNG 格式
header('Content-Type: image/png');
imagepng($im);
// 释放内存中的图像资源
imagedestroy($im);
?>
imagecreatetruecolor()
函数创建一个 100x100 像素的真彩色图像。imagecolorallocate()
函数为图像分配颜色,这里分配了白色和黑色。imagefill()
函数将图像背景填充为白色。imagerectangle()
函数在图像上绘制一个黑色的矩形。header()
设置内容类型为 image/png
,然后使用 imagepng()
函数将图像以 PNG 格式输出到浏览器或文件。imagedestroy()
函数释放图像资源,避免内存泄漏。上一篇:php querylist
下一篇:php object转array
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站