imagefontwidth()函数是PHP中的内置函数,用于获取指定字体中字符的像素宽度。
用法:
int imagefontwidth( int $font )
参数:该函数接受一个包含字体的单个参数$font。对于内置字体,它可以是1、2、3、4、5。对于自定义字体,它可以与imageloadfont()一起使用。
返回值:此函数返回一个包含字体宽度的整数值。
以下示例程序旨在说明PHP中的imagefontwidth()函数:
程序1:
// Get the font width
echo 'Font width for font value 1 is '
. imagefontwidth(1) . '
';
echo 'Font width for font value 2 is '
. imagefontwidth(2) . '
';
echo 'Font width for font value 3 is '
. imagefontwidth(3) . '
';
echo 'Font width for font value 4 is '
. imagefontwidth(4) . '
';
echo 'Font width for font value 5 is '
. imagefontwidth(5) . '
';
?>
输出:
Font width for font value 1 is 5
Font width for font value 2 is 6
Font width for font value 3 is 7
Font width for font value 4 is 8
Font width for font value 5 is 9
程序2:
// Get the font from local folder
$font = imageloadfont('Pacifico.ttf');
// Show the output
echo 'Font width for Pacifico is '
. imagefontwidth($font);
?>
输出:
Font width for Pacifico is 5