<?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 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.imagefttext.php',
    1 => 'imagefttext',
    2 => 'Write text to the image using fonts using FreeType 2',
  ),
  'up' => 
  array (
    0 => 'ref.image.php',
    1 => 'GD and Image Functions',
  ),
  'prev' => 
  array (
    0 => 'function.imageftbbox.php',
    1 => 'imageftbbox',
  ),
  'next' => 
  array (
    0 => 'function.imagegammacorrect.php',
    1 => 'imagegammacorrect',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/image/functions/imagefttext.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.imagefttext" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imagefttext</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.7, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">imagefttext</span> &mdash; <span class="dc-title">Write text to the image using fonts using FreeType 2</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.imagefttext-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>imagefttext</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="class.gdimage.php" class="type GdImage">GdImage</a></span> <code class="parameter">$image</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">$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.integer.php" class="type int">int</a></span> <code class="parameter">$x</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$y</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$color</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">$text</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>

  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Prior to PHP 8.0.0, <span class="function"><strong>imagefttext()</strong></span> was an extended variant of
    <span class="function"><a href="function.imagettftext.php" class="function">imagettftext()</a></span> which additionally supported the
    <code class="parameter">options</code>.
    As of PHP 8.0.0, <span class="function"><a href="function.imagettftext.php" class="function">imagettftext()</a></span> is an alias of <span class="function"><strong>imagefttext()</strong></span>.
   </p>
  </p></blockquote>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imagefttext-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    <dt>
<code class="parameter">image</code></dt><dd><p class="para">A <span class="classname"><a href="class.gdimage.php" class="classname">GdImage</a></span> object, returned by one of the image creation functions,
such as <span class="function"><a href="function.imagecreatetruecolor.php" class="function">imagecreatetruecolor()</a></span>.</p></dd>
    
     <dt><code class="parameter">size</code></dt>
     <dd>
      <p class="para">
       The font size to use in points.
      </p>
     </dd>
    
    
     <dt><code class="parameter">angle</code></dt>
     <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><code class="parameter">x</code></dt>
     <dd>
      <p class="para">
       The coordinates given by <code class="parameter">x</code> and
       <code class="parameter">y</code> 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.php" class="function">imagestring()</a></span>, where
       <code class="parameter">x</code> and <code class="parameter">y</code> define the
       upper-left corner of the first character. For example, &quot;top left&quot;
       is 0, 0.
      </p>
     </dd>
    
    
     <dt><code class="parameter">y</code></dt>
     <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><code class="parameter">color</code></dt>
     <dd>
      <p class="para">
       The index of the desired color for the text, see 
       <span class="function"><a href="function.imagecolorexact.php" class="function">imagecolorexact()</a></span>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">font_filename</code></dt>
     <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>when
       <code class="parameter">font_filename</code> does not begin with a leading
       <code class="literal">/</code> then <code class="literal">.ttf</code> 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">
       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">// Set the environment variable for GD<br /></span><span style="color: #0000BB">putenv</span><span style="color: #007700">(</span><span style="color: #DD0000">'GDFONTPATH=' </span><span style="color: #007700">. </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">// Name the font to be used (note the lack of the .ttf extension)<br /></span><span style="color: #0000BB">$font </span><span style="color: #007700">= </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><code class="parameter">text</code></dt>
     <dd>
      <p class="para">
       Text to be inserted into image. 
      </p>
     </dd>
    
    
     <dt><code class="parameter">options</code></dt>
     <dd>
      <p class="para">
       <table class="doctable table">
       <caption><strong>Possible array indexes for <code class="parameter">options</code></strong></caption>
        
         <thead>
          <tr>
           <th>Key</th>
           <th>Type</th>
           <th>Meaning</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>Defines drawing linespacing</td>
          </tr>

         </tbody>
        
       </table>

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

 <div class="refsect1 returnvalues" id="refsect1-function.imagefttext-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   This function returns an array defining the four points of the box, starting in the lower left and moving counter-clockwise:
   <table class="doctable informaltable">
    
     <tbody class="tbody">
      <tr>
       <td>0</td>
       <td>lower left x-coordinate</td>
      </tr>

      <tr>
       <td>1</td>
       <td>lower left y-coordinate</td>
      </tr>

      <tr>
       <td>2</td>
       <td>lower right x-coordinate</td>
      </tr>

      <tr>
       <td>3</td>
       <td>lower right y-coordinate</td>
      </tr>

      <tr>
       <td>4</td>
       <td>upper right x-coordinate</td>
      </tr>

      <tr>
       <td>5</td>
       <td>upper right y-coordinate</td>
      </tr>

      <tr>
       <td>6</td>
       <td>upper left x-coordinate</td>
      </tr>

      <tr>
       <td>7</td>
       <td>upper left y-coordinate</td>
      </tr>

     </tbody>
    
   </table>

  </p>
  <p class="para">
   On failure, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> is returned.
  </p>
 </div>


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

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.0.0</td>
 <td>
  <code class="parameter">image</code> expects a <span class="classname"><a href="class.gdimage.php" class="classname">GdImage</a></span>
  instance now; previously, a valid <code class="literal">gd</code> <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> was expected.
 </td>
</tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.imagefttext-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 <span class="function"><strong>imagefttext()</strong></span> example</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">// Create a 300x100 image<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">100</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$red </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">0xFF</span><span style="color: #007700">, </span><span style="color: #0000BB">0x00</span><span style="color: #007700">, </span><span style="color: #0000BB">0x00</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">0x00</span><span style="color: #007700">, </span><span style="color: #0000BB">0x00</span><span style="color: #007700">, </span><span style="color: #0000BB">0x00</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Make the background red<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">99</span><span style="color: #007700">, </span><span style="color: #0000BB">$red</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Path to our ttf font file<br /></span><span style="color: #0000BB">$font_file </span><span style="color: #007700">= </span><span style="color: #DD0000">'./arial.ttf'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Draw the text 'PHP Manual' using font size 13<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">13</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">105</span><span style="color: #007700">, </span><span style="color: #0000BB">55</span><span style="color: #007700">, </span><span style="color: #0000BB">$black</span><span style="color: #007700">, </span><span style="color: #0000BB">$font_file</span><span style="color: #007700">, </span><span style="color: #DD0000">'PHP Manual'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Output image to the browser<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.imagefttext-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">This function is only available if
PHP is compiled with freetype support (<strong class="option configure">--with-freetype-dir=DIR</strong>)
</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.imagefttext-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.imageftbbox.php" class="function" rel="rdfs-seeAlso">imageftbbox()</a> - Give the bounding box of a text using fonts via freetype2</span></li>
   <li><span class="function"><a href="function.imagettftext.php" class="function" rel="rdfs-seeAlso">imagettftext()</a> - Write text to the image using TrueType fonts</span></li>
  </ul>
 </div>

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