Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 3734

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Write text to the image using TrueType fonts</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.imagettfbbox.html">imagettfbbox</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.imagetypes.html">imagetypes</a></div>
 <div class="up"><a href="ref.image.html">GD and Image Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.imagettftext" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imagettftext</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">imagettftext</span> &mdash; <span class="dc-title">Write text to the image using TrueType fonts</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.imagettftext-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><strong>imagettftext</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$image</code></span>
   , <span class="methodparam"><span class="type">float</span> <code class="parameter">$size</code></span>
   , <span class="methodparam"><span class="type">float</span> <code class="parameter">$angle</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$x</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$y</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$color</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$fontfile</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$text</code></span>
   )</div>

  <p class="para rdfs-comment">
   Writes the given <em><code class="parameter">text</code></em> into the image using TrueType
   fonts.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imagettftext-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>
<span class="term"><em><code class="parameter">
image</code></em></span><dd>
<p class="para">An image resource, returned by one of the image creation functions,
such as  <span class="function"><a href="function.imagecreatetruecolor.html" class="function">imagecreatetruecolor()</a></span>.</p></dd>
</dt>

    <dt>

     <span class="term"><em><code class="parameter">size</code></em></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"><em><code class="parameter">angle</code></em></span>
     <dd>

      <p class="para">
       The angle in degrees, with 0 degrees being left-to-right reading text.
       Higher values represent a counter-clockwise rotation. For example, a 
       value of 90 would result in bottom-to-top reading text.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">x</code></em></span>
     <dd>

      <p class="para">
       The coordinates given by <em><code class="parameter">x</code></em> and
       <em><code class="parameter">y</code></em> will define the basepoint of the first
       character (roughly the lower-left corner of the character). This
       is different from the  <span class="function"><a href="function.imagestring.html" class="function">imagestring()</a></span>, where
       <em><code class="parameter">x</code></em> and <em><code class="parameter">y</code></em> define the
       upper-left corner of the first character. For example, &quot;top left&quot;
       is 0, 0.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">y</code></em></span>
     <dd>

      <p class="para">
       The y-ordinate. This sets the position of the fonts baseline, not the
       very bottom of the character.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">color</code></em></span>
     <dd>

      <p class="para">
       The color index. Using the negative of a color index has the effect of
       turning off antialiasing. See  <span class="function"><a href="function.imagecolorallocate.html" class="function">imagecolorallocate()</a></span>.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">fontfile</code></em></span>
     <dd>

      <p class="para">
       The path to the TrueType font you wish to use.
      </p>
      <p class="para">
       Depending on which version of the GD library PHP is using, <em class="emphasis">when
       <em><code class="parameter">fontfile</code></em> does not begin with a leading
       <em>/</em> then <em>.ttf</em> will be appended</em>
       to the filename and the library will attempt to search for that
       filename along a library-defined font path.
      </p>
      <p class="para">
       When using versions of the GD library lower than 2.0.18, a <em>space</em> character,
       rather than a semicolon, was used as the &#039;path separator&#039; for different font files.
       Unintentional use of this feature will result in the warning message:
       <em>Warning: Could not find/open font</em>. For these affected versions, the
       only solution is moving the font to a path which does not contain spaces.
      </p>
      <p class="para">
       In many cases where a font resides in the same directory as the script using it
       the following trick will alleviate any include problems.
       <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;Set&nbsp;the&nbsp;enviroment&nbsp;variable&nbsp;for&nbsp;GD<br /></span><span style="color: #0000BB">putenv</span><span style="color: #007700">(</span><span style="color: #DD0000">'GDFONTPATH='&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">realpath</span><span style="color: #007700">(</span><span style="color: #DD0000">'.'</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;Name&nbsp;the&nbsp;font&nbsp;to&nbsp;be&nbsp;used&nbsp;(note&nbsp;the&nbsp;lack&nbsp;of&nbsp;the&nbsp;.ttf&nbsp;extension)<br /></span><span style="color: #0000BB">$font&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'SomeFont'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
       </div>

      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">text</code></em></span>
     <dd>

      <p class="para">
       The text string in UTF-8 encoding.
      </p>
      <p class="para">
       May include decimal numeric character references (of the form:
       &amp;#8364;) to access characters in a font beyond position 127.
       The hexadecimal format (like &amp;#xA9;) is supported.
       Strings in UTF-8 encoding can be passed directly.
      </p>
      <p class="para">
       Named entities, such as &amp;copy;, are not supported. Consider using 
        <span class="function"><a href="function.html-entity-decode.html" class="function">html_entity_decode()</a></span>
       to decode these named entities into UTF-8 strings.
      </p>
      <p class="para">
       If a character is used in the string which is not supported by the
       font, a hollow rectangle will replace the character.
      </p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.imagettftext-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns an array with 8 elements representing four points making the
   bounding box of the text. The order of the points is lower left, lower 
   right, upper right, upper left. The points are relative to the text
   regardless of the angle, so &quot;upper left&quot; means in the top left-hand 
   corner when you see the text horizontally.
   Returns <strong><code>FALSE</code></strong> on error.
  </p>
 </div>

 <div class="refsect1 changelog" id="refsect1-function.imagettftext-changelog">
  <h3 class="title">Changelog</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.2.0</td>
       <td>
        It is now possible to specify an hexadecimal entity in 
        <em><code class="parameter">text</code></em>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.imagettftext-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-3286">
    <p><strong>Example #1  <span class="function"><strong>imagettftext()</strong></span> example</strong></p>
    <div class="example-contents"><p>
     This example script will produce a white PNG 400x30 pixels, with
     the words &quot;Testing...&quot; in black (with grey shadow), in the font Arial.
    </p></div>
    <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;Set&nbsp;the&nbsp;content-type<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: #FF8000">//&nbsp;Create&nbsp;the&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">400</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">30</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Create&nbsp;some&nbsp;colors<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 /></span><span style="color: #0000BB">$grey&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">128</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">128</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">128</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">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">399</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">29</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;The&nbsp;text&nbsp;to&nbsp;draw<br /></span><span style="color: #0000BB">$text&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Testing...'</span><span style="color: #007700">;<br /></span><span style="color: #FF8000">//&nbsp;Replace&nbsp;path&nbsp;by&nbsp;your&nbsp;own&nbsp;font&nbsp;path<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;Add&nbsp;some&nbsp;shadow&nbsp;to&nbsp;the&nbsp;text<br /></span><span style="color: #0000BB">imagettftext</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">20</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">11</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">21</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$grey</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$font</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$text</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Add&nbsp;the&nbsp;text<br /></span><span style="color: #0000BB">imagettftext</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">20</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">20</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: #0000BB">$text</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Using&nbsp;imagepng()&nbsp;results&nbsp;in&nbsp;clearer&nbsp;text&nbsp;compared&nbsp;with&nbsp;imagejpeg()<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 class="example-contents"><p>The above example will output
something similar to:</p></div>
    <div class="mediaobject">
     
     <div class="imageobject">
      <img src="images/21009b70229598c6a80eef8b45bf282b-imagettftext.png" alt="Output of example : imagettftext()" width="400" height="30" />
     </div>
    </div>
   </div>
  </p>
 </div>

 <div class="refsect1 notes" id="refsect1-function.imagettftext-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    This function requires both the GD library and the <a href="http://www.freetype.org/" class="link external">&raquo;&nbsp;FreeType</a> library.
   </p>
  </p></blockquote>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.imagettftext-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"> <span class="function"><a href="function.imagettfbbox.html" class="function" rel="rdfs-seeAlso">imagettfbbox()</a> - Give the bounding box of a text using TrueType fonts</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.imagettfbbox.html">imagettfbbox</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.imagetypes.html">imagetypes</a></div>
 <div class="up"><a href="ref.image.html">GD and Image Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>