在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
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站