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


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

語法

int imagefontwidth(int $font)

引數

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

返回值

imagefontwidth() 返回字型的畫素寬度。

示例 1

 現場演示

<?php
   // font width values can be changed from 1 to 5.
   echo 'Font width: '.imagefontwidth(3);
?>

輸出

Font width: 7

示例 2

 現場演示

<?php
   // Set the font width from 1 to 5
   echo 'Font width for the font value 1 is'
      .imagefontwidth(1).'<br>';

   echo 'Font width for the font value 2 is'
      .imagefontwidth(2).'<br>';

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

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

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

輸出

Font width for the font value 1 is 5
Font width for the font value 2 is 6
Font width for the font value 3 is 7
Font width for the font value 4 is 8
Font width for the font value 5 is 9

更新於: 2021 年 8 月 9 日

508 次瀏覽

開啟你的 職業生涯

完成課程即可獲得認證

開始
廣告
© . All rights reserved.