array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.imageloadfont.php', 1 => 'imageloadfont', ), 'up' => array ( 0 => 'ref.image.php', 1 => 'GD 和图像处理 函数', ), 'prev' => array ( 0 => 'function.imageline.php', 1 => 'imageline', ), 'next' => array ( 0 => 'function.imageopenpolygon.php', 1 => 'imageopenpolygon', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/image/functions/imageloadfont.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
imageloadfont — 载入新字体
filename
字体文件格式目前是二进制且依赖于体系结构。这意味着应该用跟运行 PHP 相同类型 CPU 的机器生成字体。
字节位置 | C 数据类型 | 说明 |
---|---|---|
byte 0-3 | int | 字体中的字符数 |
byte 4-7 | int | 字体中第一个字符的值(通常 32 代表空格) |
byte 8-11 | int | 每个字符宽度的像素值 |
byte 12-15 | int | 每个字符高度的像素值 |
byte 16- | char | 字符数据的数组,每字符中每像素 1 字节,一共(nchars*width*height)字节。 |
示例 #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);
?>