如何使用 PHP 中的 imagefontheight() 函数获取指定字体中字符的像素高度?

phpserver side programmingprogramming

imagefontheight() 是 PHP 中的内置函数,用于获取指定字体中字符的像素高度。

语法

int imagefontheight(int $font)

参数

imagefontheight() 接受一个参数 $font。它保存字体值。对于内置字体,$font 值可以是 1、2、3、4 和 5,对于自定义字体,也可以使用 imageloadfont() 函数。

返回值

imagefontheight() 返回字体的像素高度。

示例 1

<?php
   // 字体高度值可以从 1 更改为 5。
   echo 'Font height: ' . imagefontheight(3);
?>

输出

Font height:13

示例 2

<?php
   // 获取字体高度,范围从 1 到 5
   echo '字体值为 1 时的字体高度为'
   .imagefontheight(1) .'<br>'; //<br> 用于换行
   echo 'Font height for the font value 2 is'
   .imagefontheight(2) . '<br>';

   echo 'Font height for the font value 3 is'
   .imagefontheight(3) . '<br>';

   echo 'Font height for the font value 4 is'
   .imagefontheight(4) .'<br>';

   echo 'Font height for the font value 5 is '
   .imagefontheight(5) .'<br>';
?>

输出

Font height for the font value 1 is 8
Font height for the font value 2 is 13
Font height for the font value 3 is 13
Font height for the font value 4 is 16
Font height for the font value 5 is 15

相关文章