首页 话题 小组 问答 好文 用户 我的社区 域名交易 唠叨

[函数]imagecharup()函数—用法及示例

发布于 2025-04-27 13:28:41
0
29

函数名:imagecharup()

适用版本:PHP 4, PHP 5, PHP 7

用法:该函数用于在图像上绘制一个垂直的字符。

语法:bool imagecharup ( resource $image , int $font , int $x , int $y , string $c , int $color )

参数:

  • image:图像资源,通过imagecreatetruecolor()或imagecreate()创建。
  • font:字体大小,取值范围为 1 - 5,其中 1 为最小字体。
  • x:字符左上角的 x 坐标。
  • y:字符左上角的 y 坐标。
  • c:要绘制的字符。
  • color:字符的颜色,可以是一个整数表示的 RGB 值,或使用imagecolorallocate()函数返回的颜色标识符。

返回值:成功时返回 true,失败时返回 false。

示例:

<?php
// 创建一个 200x100 的图像
$image = imagecreatetruecolor(200, 100);

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

// 设置字体颜色为红色
$textColor = imagecolorallocate($image, 255, 0, 0);

// 在图像上绘制一个垂直的字符
imagecharup($image, 5, 50, 50, 'A', $textColor);

// 输出图像到浏览器
header('Content-Type: image/png');
imagepng($image);

// 释放图像资源
imagedestroy($image);
?>

以上示例创建了一个 200x100 的图像,将背景色设置为白色,字体颜色设置为红色,然后在图像上绘制了一个垂直的字符 "A",并将图像输出到浏览器。

评论
一个月内的热帖推荐
啊龙
Lv.1普通用户

9545

帖子

31

小组

3242

积分

赞助商广告
站长交流