imageloadfont

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

imageloadfont載入一新字體

說明

imageloadfont(string $file): int

imageloadfont() 加載一個用戶定義的位圖字體并返回該字體的標(biāo)識符(其值總是大于 5,因此不會和內(nèi)置字體沖突)。 在產(chǎn)生錯誤的情況下,該函數(shù)返回 false

字體文件格式目前是二進(jìn)制的且和平臺有關(guān)。這意味著應(yīng)該用和你運(yùn)行 PHP 的機(jī)器相同類型 CPU 的機(jī)器生成字體。

字體文件格式
字節(jié)位置 C 數(shù)據(jù)類型 說明
byte 0-3 int 字體中的字符數(shù)目
byte 4-7 int 字體中第一個字符的值(通常是 32 代表空格)
byte 8-11 int 每個字符寬度的像素值
byte 12-15 int 每個字符高度的像素值
byte 16- char 字符數(shù)據(jù)的數(shù)組,每字符中每像素一字節(jié),一共 (nchars*width*height) 字節(jié)。

示例 #1 使用 imageloadfont

<?php
header
("Content-type: image/png");
$im imagecreatetruecolor(5020);
$black imagecolorallocate($im000);
$white imagecolorallocate($im255255255);
imagefilledrectangle($im004919$white);
$font imageloadfont("04b.gdf");
imagestring($im$font00"Hello"$black);
imagepng($im);
?>

參見 imagefontwidth()imagefontheight()。