當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP imagefontheight()用法及代碼示例

imagefontheight()函數是PHP中的內置函數,用於獲取指定字體中字符的像素高度。

用法:

int imagefontheight( int $font )

參數:該函數接受單個參數$font,該參數保存字體值。對於內置字體,其值可以為1、2、3、4、5。對於自定義字體,其值可以與imageloadfont()一起使用。


返回值:該函數返回一個包含高度的整數值。

下麵給出的程序說明了PHP中的imagefontheight()函數:

程序1:

<?php 
  
// Get the font height 
echo 'Font height for font value 1 is '
        . imagefontheight(0) . '<br>'; 
  
echo 'Font height for font value 2 is '
        . imagefontheight(2) . '<br>'; 
  
echo 'Font height for font value 3 is '
        . imagefontheight(3) . '<br>'; 
  
echo 'Font height for font value 4 is '
        . imagefontheight(4) . '<br>'; 
  
echo 'Font height for font value 5 is '
        . imagefontheight(5) . '<br>'; 
?>

輸出:

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

程序2:

<?php 
  
// Get the font from local folder 
$font = imageloadfont('Pacifico.ttf'); 
  
// Show the output 
echo 'Font height for Pacifico is '
         . imagefontheight($font); 
?>

輸出:

Font height for Pacifico is 8

參考: https://www.php.net/manual/en/function.imagefontheight.php



相關用法


注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | imagefontheight() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。