array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'pt_BR', ), 'this' => array ( 0 => 'function.imagefontwidth.php', 1 => 'imagefontwidth', ), 'up' => array ( 0 => 'ref.image.php', 1 => 'Funções de GD e Image', ), 'prev' => array ( 0 => 'function.imagefontheight.php', 1 => 'imagefontheight', ), 'next' => array ( 0 => 'function.imageftbbox.php', 1 => 'imageftbbox', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'pt_BR', '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 — Obtém a largura da fonte
Retorna a largura da fonte, em pixels, de um caractere em determinada fonte.
font
Pode ser 1, 2, 3, 4, 5 para as fontes nativas na codificação latin2 (onde números maiores correspondem a fontes maiores) ou uma instância de GdFont, retornada por imageloadfont().
Retorna a largura da fonte em pixels.
Versão | Descrição |
---|---|
8.1.0 |
O parâmetro font agora aceita uma instância de GdFont
ou um int; anteriormente, apenas int era aceito.
|
Exemplo #1 Usando imagefontwidth() em fontes internas
<?php
echo 'Largura da fonte: ' . imagefontwidth(4);
?>
O exemplo acima produzirá algo semelhante a:
Largura da fonte: 8
Exemplo #2 Usando imagefontwidth() junto com imageloadfont()
<?php
// Carrega uma fonte .gdf
$font = imageloadfont('anonymous.gdf');
echo 'Largura da fonte: ' . imagefontwidth($font);
?>
O exemplo acima produzirá algo semelhante a:
Largura da fonte: 23