imageloadfont

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

imageloadfont载入新字体

说明

imageloadfont(string$filename): GdFont|false

imageloadfont() 加载用户定义的点阵字体并返回其标识符。

参数

filename

字体文件格式目前是二进制且依赖于体系结构。这意味着应该用跟运行 PHP 相同类型 CPU 的机器生成字体。

字体文件格式
字节位置C 数据类型说明
byte 0-3int字体中的字符数
byte 4-7int 字体中第一个字符的值(通常 32 代表空格)
byte 8-11int每个字符宽度的像素值
byte 12-15int每个字符高度的像素值
byte 16-char 字符数据的数组,每字符中每像素 1 字节,一共(nchars*width*height)字节。

返回值

返回 GdFont 实例, 或者在失败时返回 false

更新日志

版本说明
8.1.0 现在返回 GdFont 实例;之前返回 int

示例

示例 #1 imageloadfont() 用法示例

<?php
// Create a new image instance
$im = imagecreatetruecolor(50, 20);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);

// Make the background white
imagefilledrectangle($im, 0, 0, 49, 19, $white);

// Load the gd font and write 'Hello'
$font = imageloadfont('./04b.gdf');
imagestring($im, $font, 0, 0, 'Hello', $black);

// Output to browser
header('Content-type: image/png');

imagepng($im);
imagedestroy($im);
?>

参见

To Top