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 クラスのインスタンスと数値を両方受け入れるようになりました。これより前のバージョンでは、数値のみを受け入れていました。
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
-7
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