imagefontwidth

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

imagefontwidth获取字体宽度

说明

imagefontwidth(GdFont|int $font): int

返回字体中字符的像素宽度。

参数

font

取值对于内建的 latin2 编码字体可以是:1、2、3、4、5(更高的数字对应更大的字体), 或是通过 imageloadfont() 返回的 GdFont 实例。

返回值

返回字体的像素宽度。

更新日志

版本 说明
8.1.0 font 参数现在接受 GdFont 实例和 int,之前仅接受 int

范例

示例 #1 在内置字体上使用 imagefontwidth()

<?php
echo 'Font width: ' . imagefontwidth(4);
?>

以上例程的输出类似于:

Font width: 8

示例 #2 将 imagefontwidth()imageloadfont() 一起使用

<?php
// Load a .gdf font
$font = imageloadfont('anonymous.gdf');

echo
'Font width: ' . imagefontwidth($font);
?>

以上例程的输出类似于:

Font width: 23

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top