function.imageftbbox.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 269 行

HTML
269
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Give the bounding box of a text using fonts via freetype2</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.imagefontwidth.html">imagefontwidth</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.imagefttext.html">imagefttext</a></div> <div class="up"><a href="ref.image.html">GD Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><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)</p><p class="refpurpose"><span class="refname">imageftbbox</span> &mdash; <span class="dc-title">Give the bounding box of a text using fonts via freetype2</span></p> </div> <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type">array</span> <span class="methodname"><b><b>imageftbbox</b></b></span>    ( <span class="methodparam"><span class="type">float</span> <tt class="parameter">$size</tt></span>   , <span class="methodparam"><span class="type">float</span> <tt class="parameter">$angle</tt></span>   , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$fontfile</tt></span>   , <span class="methodparam"><span class="type">string</span> <tt class="parameter">$text</tt></span>   [, <span class="methodparam"><span class="type">array</span> <tt class="parameter">$extrainfo</tt></span>  ] )</div>  <p class="para rdfs-comment">   This function calculates and returns the bounding box in pixels   for a FreeType text.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">size</tt></i></span>     <dd>      <p class="para">       The font size. Depending on your version of GD, this should be       specified as the pixel size (GD1) or point size (GD2).      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">angle</tt></i></span>     <dd>      <p class="para">       Angle in degrees in which <i><tt class="parameter">text</tt></i> will be        measured.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">fontfile</tt></i></span>     <dd>      <p class="para">       The name of the TrueType font file (can be a URL). Depending on       which version of the GD library that PHP is using, it may attempt to       search for files that do not begin with a leading &#039;/&#039; by appending       &#039;.ttf&#039; to the filename and searching along a library-defined font path.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">text</tt></i></span>     <dd>      <p class="para">       The string to be measured.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">extrainfo</tt></i></span>     <dd>      <p class="para">       <table border="5">       <caption><b>Possible array indexes for <i><tt class="parameter">extrainfo</tt></i></b></caption>        <colgroup>         <thead valign="middle">          <tr valign="middle">           <th colspan="1">Key</th>           <th colspan="1">Type</th>           <th colspan="1">Meaning</th>          </tr>         </thead>         <tbody valign="middle" class="tbody">          <tr valign="middle">           <td colspan="1" rowspan="1" align="left"><i>linespacing</i></td>           <td colspan="1" rowspan="1" align="left"><a href="language.types.float.html" class="type float">float</a></td>           <td colspan="1" rowspan="1" align="left">Defines drawing linespacing</td>          </tr>         </tbody>        </colgroup>       </table>      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   <b>imageftbbox()</b> returns an array with 8   elements representing four points making the bounding box of the   text:   <table class="informaltable">    <colgroup>     <tbody valign="middle" class="tbody">      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">0</td>       <td colspan="1" rowspan="1" align="left">lower left corner, X position</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">1</td>       <td colspan="1" rowspan="1" align="left">lower left corner, Y position</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">2</td>       <td colspan="1" rowspan="1" align="left">lower right corner, X position</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">3</td>       <td colspan="1" rowspan="1" align="left">lower right corner, Y position</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">4</td>       <td colspan="1" rowspan="1" align="left">upper right corner, X position</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">5</td>       <td colspan="1" rowspan="1" align="left">upper right corner, Y position</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">6</td>       <td colspan="1" rowspan="1" align="left">upper left corner, X position</td>      </tr>      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">7</td>       <td colspan="1" rowspan="1" align="left">upper left corner, Y position</td>      </tr>     </tbody>    </colgroup>   </table>  </p>  <p class="para">   The points are relative to the <em class="emphasis">text</em> regardless of the   <i><tt class="parameter">angle</tt></i>, so &quot;upper left&quot; means in the top left-hand    corner seeing the text horizontally.  </p> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 <b>imageftbbox()</b> example</b></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">//&nbsp;Create&nbsp;a&nbsp;300x150&nbsp;image<br /></span><span style="color: #0000BB">$im&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecreatetruecolor</span><span style="color: #007700">(</span><span style="color: #0000BB">300</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">150</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$black&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecolorallocate</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$white&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecolorallocate</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">255</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">255</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">255</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Set&nbsp;the&nbsp;background&nbsp;to&nbsp;be&nbsp;white<br /></span><span style="color: #0000BB">imagefilledrectangle</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">299</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">299</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$white</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Path&nbsp;to&nbsp;our&nbsp;font&nbsp;file<br /></span><span style="color: #0000BB">$font&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'./arial.ttf'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;First&nbsp;we&nbsp;create&nbsp;our&nbsp;bounding&nbsp;box<br /></span><span style="color: #0000BB">$bbox&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imageftbbox</span><span style="color: #007700">(</span><span style="color: #0000BB">10</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$font</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'The&nbsp;PHP&nbsp;Documentation&nbsp;Group'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;This&nbsp;is&nbsp;our&nbsp;cordinates&nbsp;for&nbsp;X&nbsp;and&nbsp;Y<br /></span><span style="color: #0000BB">$x&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$bbox</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">]&nbsp;+&nbsp;(</span><span style="color: #0000BB">imagesx</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">)&nbsp;/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;-&nbsp;(</span><span style="color: #0000BB">$bbox</span><span style="color: #007700">[</span><span style="color: #0000BB">4</span><span style="color: #007700">]&nbsp;/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;-&nbsp;</span><span style="color: #0000BB">5</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$y&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$bbox</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]&nbsp;+&nbsp;(</span><span style="color: #0000BB">imagesy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">)&nbsp;/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;-&nbsp;(</span><span style="color: #0000BB">$bbox</span><span style="color: #007700">[</span><span style="color: #0000BB">5</span><span style="color: #007700">]&nbsp;/&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">)&nbsp;-&nbsp;</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">,&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$x</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$y</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$black</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$font</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'The&nbsp;PHP&nbsp;Documentation&nbsp;Group'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Output&nbsp;to&nbsp;browser<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-type:&nbsp;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">imagedestroy</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">  <h3 class="title">Notes</h3>  <blockquote><p><b class="note">Note</b>: <span class="simpara">This function requires GD 2.0.1 or later (2.0.28 or later is recommended).</span></p></blockquote>  <blockquote><p><b class="note">Note</b>: <span class="simpara">This function is only available ifPHP is compiled with freetype support (<span class="option">--with-freetype-dir=DIR</span>)</span></p></blockquote> </div> <div class="refsect1 changelog">  <h3 class="title">ChangeLog</h3>  <p class="para">   <table class="informaltable">    <colgroup>     <thead valign="middle">      <tr valign="middle">       <th colspan="1">Version</th>       <th colspan="1">Description</th>      </tr>     </thead>     <tbody valign="middle" class="tbody">      <tr valign="middle">       <td colspan="1" rowspan="1" align="left">4.3.5</td>       <td colspan="1" rowspan="1" align="left">        <i><tt class="parameter">extrainfo</tt></i> was made optional.       </td>      </tr>     </tbody>    </colgroup>   </table>  </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.imagefontwidth.html">imagefontwidth</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.imagefttext.html">imagefttext</a></div> <div class="up"><a href="ref.image.html">GD Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?