水平地畫一行字串

imagestring

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

imagestring — 水平地畫一行字串

說明

imagestring(
    resource $image,
    int $font,
    int $x,
    int $y,
    string $s,
    int $col
): bool

imagestring() 用 col 顏色將字串 s 畫到 image 所代表的影象的 x,y 座標處(這是字串左上角座標,整幅影象的左上角為 0,0)。如果 font 是 1,2,3,4 或 5,則使用內建字型。

示例 #1 imagestring() 例子

<?php
// 建立一幅 100X30 的影象
$im = imagecreate(100, 30);

// 白色背景和藍色文字
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);

// 把字串寫在影象左上角
imagestring($im, 5, 0, 0, "Hello world!", $textcolor);

// 輸出影象
header("Content-type: image/png");
imagepng($im);
?>

參見 imageloadfont() 和 imagettftext()。

Leave a Reply

Your email address will not be published. Required fields are marked *