How to get the pixel height of a character in the specified font using the imagefontheight() function in PHP?


imagefontheight() is an inbuilt function in PHP that is used to get the pixel height of a character in the specified font.

Syntax

int imagefontheight(int $font)

Parameters

imagefontheight() takes one parameter, $font. It holds the font value. The $font values can be 1, 2, 3, 4, and 5 for the built-in fonts or it can be used by using imageloadfont() function for custom fonts.

Return Values

imagefontheight() returns the pixel height of the font.

Example 1

 Live Demo

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

Output

Font height: 13

Example 2

Live Demo

<?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>';
?>

Output

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

Updated on: 09-Aug-2021

208 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements