Open In App

PHP | imagefontwidth() Function

Last Updated : 14 Feb, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
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
<?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
<?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

Next Article

Similar Reads