<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.image.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.imageftbbox.php',
    1 => 'imageftbbox',
    2 => '通过 freetype2 使用字体给出文本的边界框',
  ),
  'up' => 
  array (
    0 => 'ref.image.php',
    1 => 'GD 和图像处理 函数',
  ),
  'prev' => 
  array (
    0 => 'function.imagefontwidth.php',
    1 => 'imagefontwidth',
  ),
  'next' => 
  array (
    0 => 'function.imagefttext.php',
    1 => 'imagefttext',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'zh',
    'path' => 'reference/image/functions/imageftbbox.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.imageftbbox" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imageftbbox</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.7, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">imageftbbox</span> &mdash; <span class="dc-title">通过 freetype2 使用字体给出文本的边界框</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.imageftbbox-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>imageftbbox</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.float.php" class="type float">float</a></span> <code class="parameter">$size</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.float.php" class="type float">float</a></span> <code class="parameter">$angle</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$font_filename</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$string</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$options</code><span class="initializer"> = []</span></span><br>): <span class="type"><span class="type"><a href="language.types.array.php" class="type array">array</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   此函数计算并返回 FreeType 文本的边界框（以像素为单位）。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    在 PHP 8.0.0 之前，<span class="function"><strong>imageftbbox()</strong></span> 是 <span class="function"><a href="function.imagettfbbox.php" class="function">imagettfbbox()</a></span> 的扩展变体，它还支持
    <code class="parameter">options</code>。自 PHP 8.0.0 起，<span class="function"><a href="function.imagettfbbox.php" class="function">imagettfbbox()</a></span> 是
    <span class="function"><strong>imageftbbox()</strong></span> 的别名。
   </p>
  </p></blockquote>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imageftbbox-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">size</code></dt>
     <dd>
      <p class="para">字体的尺寸，单位：点（磅）。</p>
     </dd>
    
    
     <dt><code class="parameter">angle</code></dt>
     <dd>
      <p class="para">
       测量的 <code class="parameter">string</code> 的角度（以度为单位）。
      </p>
     </dd>
    
    
     <dt><code class="parameter">font_filename</code></dt>
     <dd>
      <p class="para">
       TrueType 字体文件的名称（可以是 URL）。根据 PHP 使用的 GD
       库的版本，可能会尝试搜索没有以“/”开头并会在末尾追加“.ttf”的文件名，并沿着库定义的字体路径搜索。
      </p>
     </dd>
    
    
     <dt><code class="parameter">string</code></dt>
     <dd>
      <p class="para">
       要测量的字符串。
      </p>
     </dd>
    
    
     <dt><code class="parameter">options</code></dt>
     <dd>
      <p class="para">
       <table class="doctable table">
       <caption><strong><code class="parameter">options</code> 可能的数组索引</strong></caption>
        
         <thead>
          <tr>
           <th>键</th>
           <th>类型</th>
           <th>含义</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td><code class="literal">linespacing</code></td>
           <td><span class="type"><a href="language.types.float.php" class="type float">float</a></span></td>
           <td>定义绘制行距</td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.imageftbbox-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   <span class="function"><strong>imageftbbox()</strong></span> 返回包含 8 个元素的数组，代表构成文本边界框的四个点：
   <table class="doctable informaltable">
    
     <tbody class="tbody">
      <tr>
       <td>0</td>
       <td>左下角，X 坐标</td>
      </tr>

      <tr>
       <td>1</td>
       <td>左下角，Y 坐标</td>
      </tr>

      <tr>
       <td>2</td>
       <td>右下角，X 坐标</td>
      </tr>

      <tr>
       <td>3</td>
       <td>右下角，Y 坐标</td>
      </tr>

      <tr>
       <td>4</td>
       <td>右上角，X 坐标</td>
      </tr>

      <tr>
       <td>5</td>
       <td>右上角， Y 坐标</td>
      </tr>

      <tr>
       <td>6</td>
       <td>左上角，X 坐标</td>
      </tr>

      <tr>
       <td>7</td>
       <td>左上角，Y 坐标</td>
      </tr>

     </tbody>
    
   </table>

  </p>
  <p class="para">
   无论 <code class="parameter">angle</code> 如何，这些点都是相对于
   <em>text</em>，因此“左上角”意味着在左上角水平地看到文本。
  </p>
  <p class="para">
   失败时，返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>。
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.imageftbbox-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 <span class="function"><strong>imageftbbox()</strong></span> 示例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// 创建 300x150 图像<br /></span><span style="color: #0000BB">$im </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecreatetruecolor</span><span style="color: #007700">(</span><span style="color: #0000BB">300</span><span style="color: #007700">, </span><span style="color: #0000BB">150</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$black </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecolorallocate</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$white </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecolorallocate</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #0000BB">255</span><span style="color: #007700">, </span><span style="color: #0000BB">255</span><span style="color: #007700">, </span><span style="color: #0000BB">255</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// 将背景设置为白色<br /></span><span style="color: #0000BB">imagefilledrectangle</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">299</span><span style="color: #007700">, </span><span style="color: #0000BB">299</span><span style="color: #007700">, </span><span style="color: #0000BB">$white</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// 字体文件的路径<br /></span><span style="color: #0000BB">$font </span><span style="color: #007700">= </span><span style="color: #DD0000">'./arial.ttf'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// 首先创建边界框<br /></span><span style="color: #0000BB">$bbox </span><span style="color: #007700">= </span><span style="color: #0000BB">imageftbbox</span><span style="color: #007700">(</span><span style="color: #0000BB">10</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">$font</span><span style="color: #007700">, </span><span style="color: #DD0000">'The PHP Documentation Group'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// 这是 X 和 Y 坐标<br /></span><span style="color: #0000BB">$x </span><span style="color: #007700">= </span><span style="color: #0000BB">$bbox</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">] + (</span><span style="color: #0000BB">imagesx</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">) / </span><span style="color: #0000BB">2</span><span style="color: #007700">) - (</span><span style="color: #0000BB">$bbox</span><span style="color: #007700">[</span><span style="color: #0000BB">4</span><span style="color: #007700">] / </span><span style="color: #0000BB">2</span><span style="color: #007700">) - </span><span style="color: #0000BB">5</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$y </span><span style="color: #007700">= </span><span style="color: #0000BB">$bbox</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">] + (</span><span style="color: #0000BB">imagesy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">) / </span><span style="color: #0000BB">2</span><span style="color: #007700">) - (</span><span style="color: #0000BB">$bbox</span><span style="color: #007700">[</span><span style="color: #0000BB">5</span><span style="color: #007700">] / </span><span style="color: #0000BB">2</span><span style="color: #007700">) - </span><span style="color: #0000BB">5</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">imagefttext</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #0000BB">10</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">$x</span><span style="color: #007700">, </span><span style="color: #0000BB">$y</span><span style="color: #007700">, </span><span style="color: #0000BB">$black</span><span style="color: #007700">, </span><span style="color: #0000BB">$font</span><span style="color: #007700">, </span><span style="color: #DD0000">'The PHP Documentation Group'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// 输出到浏览器<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-Type: image/png'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">imagepng</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 notes" id="refsect1-function.imageftbbox-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: <span class="simpara">此函数仅在
PHP 编译时加入 freetype 支持时有效（<strong class="option configure">--with-freetype-dir=DIR</strong>）。</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.imageftbbox-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.imagefttext.php" class="function" rel="rdfs-seeAlso">imagefttext()</a> - 使用 FreeType 2 字体将文本写入图像</span></li>
   <li><span class="function"><a href="function.imagettfbbox.php" class="function" rel="rdfs-seeAlso">imagettfbbox()</a> - 取得使用 TrueType 字体的文本的边界框</span></li>
  </ul>
 </div>

</div><?php manual_footer($setup); ?>