如何使用 PHP 中的 imagefontheight() 函式獲取指定字型中字元的畫素高度?


imagefontheight() 是 PHP 中的內建函式,用於獲取指定字型中字元的畫素高度。

語法

int imagefontheight(int $font)

引數

imagefontheight() 接受一個引數,$font。它儲存字型值。$font 的值可以是 1、2、3、4 和 5(用於內建字型),也可以使用 imageloadfont() 函式自定義字型。

返回值

imagefontheight() 返回字型的畫素高度。

示例 1

 線上演示

<?php
   // font height values can be change from 1 to 5.
   echo 'Font height: ' . imagefontheight(3);
?>

輸出

Font height: 13

示例 2

線上演示

<?php
   // Get the font height from 1 to 5
   echo 'Font height for the font value 1 is'
   .imagefontheight(1) .'<br>'; //<br> is used for the line break

   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

更新於:2021年8月9日

239 次檢視

啟動您的職業生涯

完成課程獲得認證

開始學習
廣告