The imagefontwidth() function is an inbuilt function in PHP which is used to get the pixel width of a character in the specified font.
Syntax:
int imagefontwidth( int $font )
Parameters: This function accept a single parameter $font which holds the font. It can be 1, 2, 3, 4, 5 for built-in fonts or can be used with imageloadfont() for custom fonts.
Return Value: This function returns an integer value containing the font width.
Below programs illustrate the imagefontwidth() function in PHP:
Program 1:
<?php    // Get the font width echo 'Font width for font value 1 is '        . imagefontwidth(1) . '<br>';   echo 'Font width for font value 2 is '        . imagefontwidth(2) . '<br>';   echo 'Font width for font value 3 is '        . imagefontwidth(3) . '<br>';   echo 'Font width for font value 4 is '        . imagefontwidth(4) . '<br>';   echo 'Font width for font value 5 is '        . imagefontwidth(5) . '<br>'; ?> |
Output:
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
Program 2:
<?php   // Get the font from local folder $font = imageloadfont('Pacifico.ttf');   // Show the output echo 'Font width for Pacifico is '         . imagefontwidth($font); ?> |
Output:
Font width for Pacifico is 5
Reference: https://www.php.net/manual/en/function.imagefontwidth.php
