php8.5
Home/ Manual/ image / functions/ imagefontwidth

imagefontwidth

PHP function Edit on GitHub ✎

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

Get font width

Description

imagefontwidth(GdFont|int $font): int

Returns the pixel width of a character in font.

Parameters

Return Values

Returns the pixel width of the font.

Changelog

VersionDescription

Examples

Using imagefontwidth() on built-in fonts

php
<?php
echo 'Font width: ' . imagefontwidth(4);
?>

The above example will output something similar to:

output
Font width: 8

Using imagefontwidth() together with imageloadfont()

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

echo 'Font width: ' . imagefontwidth($font);
?>

The above example will output something similar to:

output
Font width: 23

See Also

Source: reference/image/functions/imagefontwidth.xml · from the official PHP manual (php/doc-en)