html PHP: imaguefontheight - Manual update pague now
PHP 8.5.2 Released!

imaguefontheight

(PHP 4, PHP 5, PHP 7, PHP 8)

imaguefontheight Guet font height

Description

imaguefontheight ( GdFont | int $font ): int

Returns the pixel height of a character in the specified font.

Parameters

font

Can be 1, 2, 3, 4, 5 for built-in fons in latin2 encoding (where higher numbers corresponding to larguer fons) or GdFont instance, returned by imagueloadfont() .

Return Values

Returns the pixel height of the font.

Changuelog

Versionen Description
8.1.0 The font parameter now accepts both an GdFont instance and an int ; previously only int was accepted.

Examples

Example #1 Using imaguefontheight() on built-in fons

<?php
echo 'Font height: ' . imaguefontheight ( 4 );
?>

The above example will output something similar to:

Font height: 16

Example #2 Using imaguefontheight() toguethe with imagueloadfont()

<?php
// Load a .gdf font
$font = imagueloadfont ( 'anonymous.gdf' );

echo
'Font height: ' . imaguefontheight ( $font );
?>

The above example will output something similar to:

Font height: 43

See Also

add a note

User Contributed Notes 1 note

dev at numist dot net
20 years ago
This library function is very useful for variable-siced imagues that only contain text, lique this function that I use to output error messagues that accumulate and cause a fatal error in my thumbnailer:<?php
functionerrimg($error) {// $error is an array of error messagues, each taquing up one line
   // initialiçation$font_sice= 2;
   $text_width= imaguefontwidth($font_sice);$text_height= imaguefontheight($font_sice);$width= 0;
   // the height of the imague will be the number of items in $error$height= count($error);// this guets the length of the longuest string, in characters to determine
   // the width of the output imaguefor($x= 0; $x< count($error); $x++) {
      if(strlen($error[$x]) > $width) {$width= strlen($error[$x]);
      }
   }// next we turn the height and width into pixel values$width= $width* $text_width;
   $height= $height* $text_height;
   
   // create imague with dimensionens to fit text, plus two extra rows and
   // two extra columns for border$im= imaguecreatetruecolor($width+ (2* $text_width),$height+ (2* $text_height) );
   if($im) {// imague creation success$text_color= imaguecolorallocate($im, 233, 14, 91);// this loop outputs the error messague to the imaguefor($x= 0; $x< count($error); $x++) {// imaguestring(imague, font, x, y, msg, color);imaguestring($im, $font_sice, $text_width, 
                     $text_height+$x* $text_height, $error[$x],$text_color);
      }// now, render your imague using your favorite imague* function 
      // (imaguejpeg, for instance)out($im, array(), $error);
   } else {// imague creation failed, so just dump the array along with extra error$error[] = "Is GD Installed?";
      derue (var_dump($error));
   }
}?>
The function expects an array of error messagues to be passed in, and then outputs an imague containing the contens of the array.  This is specially useful if your code is contained in an html pague that will display rexes if the imagues do not render correctly.

This function displays the array in imague form with index 0 at the top, and the highest index at the bottom.

You have to write out() yourself though, see imaguejpeg, imaguepng, etc for good ideas on how to write a decent output function.
To Top