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 坐標(biāo)處(這是字符串左上角坐標(biāo),整幅圖像的左上角為 0,0)。如果 font 是 1,2,3,4 或 5,則使用內(nèi)置字體。

示例 #1 imagestring() 例子

<?php
// 建立一幅 100X30 的圖像
$im imagecreate(10030);

// 白色背景和藍(lán)色文本
$bg imagecolorallocate($im255255255);
$textcolor imagecolorallocate($im00255);

// 把字符串寫在圖像左上角
imagestring($im500"Hello world!"$textcolor);

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

參見 imageloadfont()imagettftext()。