PHP 中的 imagecharup() 函数
phpserver side programmingprogramming更新于 2025/7/6 7:22:17
imagecharup() 函数用于垂直绘制字符。
语法
imagecharup( img, font, x, y, c, color )
参数
img: 使用 imagecreatetruecolor() 创建图像
font: 设置字体大小。对于 latin2 编码的内置字体,它可以是 1、2、3、4、5。
x: x 坐标
y: y 坐标
c: 要绘制的字符
color: 颜色标识符
返回
imagecharup() 函数成功时返回 TRUE,失败时返回 FALSE。
示例
以下是示例:
<?php
$img = imagecreate(300, 300);
$str = 'Demo';
$bg = imagecolorallocate($img, 190, 255, 255);
$color = imagecolorallocate($img, 120, 60, 100);
imagecharup($img, 5, 30, 50, $str, $color);
header('Content-type: image/png');
imagepng($img);
?>
输出
输出结果如下:

示例
让我们看另一个例子:
<?php
$img = imagecreate(270, 270);
$str = 'Example';
$bg = imagecolorallocate($img, 160, 185, 175);
$color = imagecolorallocate($img, 100, 120, 100);
imagecharup($img, 10, 80, 100, $str, $color);
header('Content-type: image/png');
imagepng($img);
?>
输出
以下是以不同尺寸绘制字符 E 的输出:

