PHP 8.3.4 Released!

imagecharup

(PHP 4, PHP 5, PHP 7, PHP 8)

imagecharup垂直地绘制一个字符

说明

imagecharup(
    GdImage $image,
    GdFont|int $font,
    int $x,
    int $y,
    string $char,
    int $color
): bool

在指定 image 的特定坐标处竖直绘制字符 char

参数

image

由图象创建函数(例如imagecreatetruecolor())返回的 GdImage 对象。

font

取值对于内建的 latin2 编码字体可以是:1、2、3、4、5(更高的数字对应更大的字体), 或是通过 imageloadfont() 返回的 GdFont 实例。

x

起点的 x 坐标。

y

起点的 y 坐标。

char

要绘制的字符。

color

颜色标识符使用 imagecolorallocate() 创建。

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.1.0 font 参数现在接受 GdFont 实例和 int,之前仅接受 int
8.0.0 image 现在需要 GdImage 实例;之前需要有效的 gd resource

示例

示例 #1 imagecharup() 示例

<?php

$im
= imagecreate(100, 100);

$string = 'Note that the first letter is a N';

$bg = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);

// 在白色背景上打印黑色“Z”
imagecharup($im, 3, 10, 10, $string, $black);

header('Content-type: image/png');
imagepng($im);

?>

以上示例的输出类似于:

输出示例:imagecharup()

参见

add a note

User Contributed Notes 1 note

up
-5
php at corzoogle dot com
18 years ago
<?php
// incredibly, no one has added this.
// write a string of text vertically on an image..
// ;o)

$string = '(c) corz.org';
$font_size = 2;
$img = imagecreate(20,90);
$bg = imagecolorallocate($img,225,225,225);
$black = imagecolorallocate($img,0,0,0);

$len = strlen($string);
for (
$i=1; $i<=$len; $i++) {
   
imagecharup($img, $font_size, 5, imagesy($img)-($i*imagefontwidth($font_size)), $string, $black);
   
$string = substr($string,1);
}
header('Content-type: image/png');
imagepng($img);
imagedestroy($img); // dudes! don't forget this!
?>
To Top