导航首页 » 技术教程 » PHP:imageloadfont()的用法_GD库图像处理函数
PHP:imageloadfont()的用法_GD库图像处理函数 151 2023-12-15   

imageloadfont

(PHP 4, PHP 5)

imageloadfont — 载入一新字体

说明

int imageloadfont ( string $file )

imageloadfont() 加载一个用户定义的位图字体并返回该字体的标识符(其值总是大于 5,因此不会和内置字体冲突)。 在产生错误的情况下,该函数返回 FALSE

字体文件格式目前是二进制的且和平台有关。这意味着应该用和你运行 PHP 的机器相同类型 CPU 的机器生成字体。

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

Example #1 使用 imageloadfont

<?php
header("Content-type: image/png");
$im = imagecreatetruecolor(50, 20);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, 49, 19, $white);
$font = imageloadfont("04b.gdf");
imagestring($im, $font, 0, 0, "Hello", $black);
imagepng($im);
?>

参见 imagefontwidth() 和 imagefontheight()。


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103