array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'en', ), 'this' => array ( 0 => 'function.imagefontwidth.php', 1 => 'imagefontwidth', ), 'up' => array ( 0 => 'ref.image.php', 1 => 'GD and Image Functions', ), 'prev' => array ( 0 => 'function.imagefontheight.php', 1 => 'imagefontheight', ), 'next' => array ( 0 => 'function.imageftbbox.php', 1 => 'imageftbbox', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/image/functions/imagefontwidth.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
imagefontwidth — Get font width
font
Can be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or GdFont instance, returned by imageloadfont().
Returns the pixel width of the font.
Version | Description |
---|---|
8.1.0 |
The font parameter now accepts both an GdFont instance
and an int; previously only int was accepted.
|
Example #1 Using imagefontwidth() on built-in fonts
<?php
echo 'Font width: ' . imagefontwidth(4);
?>
The above example will output something similar to:
Font width: 8
Example #2 Using imagefontwidth() together with imageloadfont()
<?php
// Load a .gdf font
$font = imageloadfont('anonymous.gdf');
echo 'Font width: ' . imagefontwidth($font);
?>
The above example will output something similar to:
Font width: 23