array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.imagefontwidth.php', 1 => 'imagefontwidth', ), 'up' => array ( 0 => 'ref.image.php', 1 => 'GD および Image 関数', ), 'prev' => array ( 0 => 'function.imagefontheight.php', 1 => 'imagefontheight', ), 'next' => array ( 0 => 'function.imageftbbox.php', 1 => 'imageftbbox', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', '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 — フォントの幅を取得する
font
latin2 エンコーディングの組み込みのフォントの場合は 1, 2, 3, 4, 5 のいずれか (数字が大きなほうが、より大きいフォントに対応します)、あるいは imageloadfont() が返した、GdFont クラスのインスタンスのいずれか。
フォントの幅をピクセルで返します。
例1 組み込みフォントでの imagefontwidth() の使用法
<?php
echo 'フォントの幅: ' . imagefontwidth(4);
?>
上の例の出力は、 たとえば以下のようになります。
フォントの幅: 8
例2 imagefontwidth() と imageloadfont() を組み合わせた使用法
<?php
// .gdf フォントを読み込みます
$font = imageloadfont('anonymous.gdf');
echo 'フォントの幅: ' . imagefontwidth($font);
?>
上の例の出力は、 たとえば以下のようになります。
フォントの幅: 23