Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

php生成占位图

作者:°妮可罗宾   发布日期:2025-11-28   浏览:32

在PHP中,可以使用GD库来生成占位图。下面是一个简单的示例代码:

<?php
// 创建一个 200x200 的空白图片
$image = imagecreatetruecolor(200, 200);

// 设置背景颜色为灰色
$bgColor = imagecolorallocate($image, 200, 200, 200);
imagefill($image, 0, 0, $bgColor);

// 设置文字颜色为白色
$textColor = imagecolorallocate($image, 255, 255, 255);

// 在图片中心写入 "Placeholder" 文字
$text = 'Placeholder';
$textWidth = imagefontwidth(5) * strlen($text);
$textHeight = imagefontheight(5);
$textX = (200 - $textWidth) / 2;
$textY = (200 - $textHeight) / 2;
imagestring($image, 5, $textX, $textY, $text, $textColor);

// 发送图片头部信息
header('Content-Type: image/png');

// 输出图片
imagepng($image);

// 释放内存
imagedestroy($image);
?>

这段代码会生成一个200x200像素的灰色背景图片,并在图片中心写入"Placeholder"文字。你可以根据需要调整图片大小、背景颜色、文字内容等。

上一篇:php 显示宽度不够

下一篇:php日期选择控件6

大家都在看

php session用法

php 定义常量

phpisset函数

php html转图片

php后端

php爬虫框架

php读取csv文件

php+mysql动态网站开发

phpmyadmin docker

php session id

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站