<?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 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.imagettftext.php',
    1 => 'imagettftext',
    2 => 'Dessine un texte avec une police TrueType',
  ),
  'up' => 
  array (
    0 => 'ref.image.php',
    1 => 'Fonctions GD et images',
  ),
  'prev' => 
  array (
    0 => 'function.imagettfbbox.php',
    1 => 'imagettfbbox',
  ),
  'next' => 
  array (
    0 => 'function.imagetypes.php',
    1 => 'imagetypes',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/image/functions/imagettftext.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.imagettftext" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imagettftext</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">imagettftext</span> &mdash; <span class="dc-title">Dessine un texte avec une police TrueType</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.imagettftext-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>imagettftext</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>

  <p class="para rdfs-comment">
   <span class="function"><strong>imagettftext()</strong></span> dessine le texte <code class="parameter">text</code>
   avec la police TrueType <code class="parameter">fontfile</code>.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Antérieur à PHP 8.0.0, <span class="function"><a href="function.imagefttext.php" class="function">imagefttext()</a></span> était une variante
    étendue de <span class="function"><strong>imagettftext()</strong></span> qui en plus supportait
    <code class="parameter">extrainfo</code>.
    À partir de PHP 8.0.0, <span class="function"><strong>imagettftext()</strong></span> est un alias de
    <span class="function"><a href="function.imagefttext.php" class="function">imagefttext()</a></span>.
   </p>
  </p></blockquote>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imagettftext-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
<dt><code class="parameter">image</code></dt><dd><p class="para">
 Un objet <span class="classname"><a href="class.gdimage.php" class="classname">GdImage</a></span>, retournée par une des fonctions de
 création d&#039;images, comme <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">La taille de la police de caractères en point.</p>
     </dd>
    
    
     <dt><code class="parameter">angle</code></dt>
     <dd>
      <p class="para">
       L&#039;angle, en degrés ; 0 degré correspond à la lecture du texte
       de gauche à droite. Les valeurs positives représentent une rotation
       dans le sens contraire des aiguilles d&#039;une montre. Par exemple,
       une valeur de 90 correspondra à une lecture du texte de bas en haut.
      </p>
     </dd>
    
    
     <dt><code class="parameter">x</code></dt>
     <dd>
      <p class="para">
       Les coordonnées données par <code class="parameter">x</code> et
       <code class="parameter">y</code> définiront la position du premier caractère
       (le coin bas-gauche du caractère). Cela est différent de la fonction
       <span class="function"><a href="function.imagestring.php" class="function">imagestring()</a></span>, où
       <code class="parameter">x</code> et <code class="parameter">y</code> définissent
       le coin haut-gauche du premier caractère. Par exemple, &quot;haut gauche&quot;
       correspond à 0, 0.
      </p>
     </dd>
    
    
     <dt><code class="parameter">y</code></dt>
     <dd>
      <p class="para">
       L&#039;ordonnée Y. Cela définit la position de la ligne de base
       de la police, et non pas le bas des caractères.
      </p>
     </dd>
    
    
     <dt><code class="parameter">color</code></dt>
     <dd>
      <p class="para">
       L&#039;index de la couleur. Utiliser un index de couleur négatif désactivera
       l&#039;antialiasing. Voir la fonction <span class="function"><a href="function.imagecolorallocate.php" class="function">imagecolorallocate()</a></span>.
      </p>
     </dd>
    
    

<dt><code class="parameter">fontfile</code></dt>
<dd>
    <p class="para">
        Le chemin d&#039;accès à la police TrueType que vous souhaitez utiliser.
    </p>
    <p class="para">
        Selon la version de la bibliothèque GD que PHP utilise, <em>quand
        <code class="parameter">fontfile</code> ne commence pas par une premier
        <code class="literal">/</code> alors <code class="literal">.ttf</code> sera ajouté</em>
        au nom de fichier et la bibliothèque essaiera de rechercher ce nom de
        fichier le long d&#039;un chemin de police défini par la bibliothèque.
    </p>
    <p class="para">
        Lorsque vous utilisez des versions de la bibliothèque GD inférieure à
        2.0.18, un caractère <code class="literal">espace</code>, plutôt qu&#039;un
        point-virgule, a été utilisé comme séparateur de chemin d&#039;accès pour
        différents fichiers de police. L&#039;utilisation involontaire de cette
        fonctionnalité se traduira par le message d&#039;avertissement: <code class="literal">
        Avertissement: impossible de trouver/ouvrir la police</code>. Pour
        ces versions affectées, la seule solution consiste à déplacer la police
        vers un chemin qui ne contient pas d&#039;espaces.
    </p>
    <p class="para">
        Dans de nombreux cas où une police réside dans le même répertoire que le
        script en l&#039;utilisant l&#039;astuce suivante permettra d&#039;atténuer les
        problèmes d&#039;inclusion.
        <div class="example-contents">
            <div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Définir la variable d'environnement pour 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">// Nommez la police à utiliser (Notez l'absence de l'extension .ttf)<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>
    <blockquote class="note"><p><strong class="note">Note</strong>: 
        <p class="para">
            Notez que <a href="ini.core.php#ini.open-basedir" class="link">open_basedir</a>
            <em>ne s&#039;applique pas</em> à <code class="parameter">fontfile</code>.
        </p>
    </p></blockquote>
</dd>


    
     <dt><code class="parameter">text</code></dt>
     <dd>
      <p class="para">
       La chaîne de texte, en UTF-8.
      </p>
      <p class="para">
       Peut inclure des références à des caractères numériques,
       décimales (sous la forme : <code class="literal">&amp;#8364;</code>) pour accéder aux caractères
       d&#039;une police au-delà du premier 127.
       Le format hexadécimal (comme <code class="literal">&amp;#xA9;</code>) est pris en charge.
       Les chaînes de caractères encodées en UTF-8 peuvent être passées directement.
      </p>
      <p class="para">
       Les entités nommées, comme <code class="literal">&amp;copy;</code>, ne sont pas supportées. Utiliser la
       fonction <span class="function"><a href="function.html-entity-decode.php" class="function">html_entity_decode()</a></span> pour encoder ces entités
       nommées en chaîne UTF-8.
      </p>
      <p class="para">
       Si un caractère est utilisé dans une chaîne qui n&#039;est pas supportée
       par la police, un rectangle creux remplacera le caractère.
      </p>
     </dd>
    
    
     <dt><code class="parameter">options</code></dt>
     <dd>
      <p class="para">
       Un tableau avec une clé <code class="literal">linespacing</code> contenant une valeur <span class="type"><a href="language.types.float.php" class="type float">float</a></span>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.imagettftext-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne un tableau de 8 éléments représentant quatre points
   marquants les limites du texte. L&#039;ordre des points est : inférieur
   gauche, inférieur droit, supérieur droit, supérieur gauche. Les
   points sont relatifs au texte par rapport à l&#039;angle, donc, &quot;supérieur
   gauche&quot; signifie dans le coin en haut à gauche lorsqu&#039;on
   regarde le texte horizontalement.
   Retourne <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> si une erreur survient.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.imagettftext-changelog">
  <h3 class="title">Historique</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>
       Le paramètre <code class="parameter">options</code> a été ajouté.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.imagettftext-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple avec <span class="function"><strong>imagettftext()</strong></span></strong></p>
    <div class="example-contents"><p>
     Cet exemple produira une image PNG blanche de 400x30 pixels,
     avec le texte <code class="literal">&quot;Test...&quot;</code> en noir, avec une ombre
     grise, utilisant la police Arial.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">// Définition du content-type<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: #FF8000">// Création de l'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">400</span><span style="color: #007700">, </span><span style="color: #0000BB">30</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Création de quelques couleurs<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 /></span><span style="color: #0000BB">$grey </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">128</span><span style="color: #007700">, </span><span style="color: #0000BB">128</span><span style="color: #007700">, </span><span style="color: #0000BB">128</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">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">399</span><span style="color: #007700">, </span><span style="color: #0000BB">29</span><span style="color: #007700">, </span><span style="color: #0000BB">$white</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Le texte à dessiner<br /></span><span style="color: #0000BB">$text </span><span style="color: #007700">= </span><span style="color: #DD0000">'Test...'</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Remplacez le chemin par votre propre chemin de police<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">// Ajout d'ombres au texte<br /></span><span style="color: #0000BB">imagettftext</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #0000BB">20</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">11</span><span style="color: #007700">, </span><span style="color: #0000BB">21</span><span style="color: #007700">, </span><span style="color: #0000BB">$grey</span><span style="color: #007700">, </span><span style="color: #0000BB">$font</span><span style="color: #007700">, </span><span style="color: #0000BB">$text</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Ajout du texte<br /></span><span style="color: #0000BB">imagettftext</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #0000BB">20</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">10</span><span style="color: #007700">, </span><span style="color: #0000BB">20</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: #0000BB">$text</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Utiliser imagepng() donnera un texte plus clair,<br />// comparé à l'utilisation de la fonction 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 /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>Résultat de l&#039;exemple ci-dessus est similaire à :</p></div>
    <div class="mediaobject">
     
     <div class="imageobject">
      <img src="images/21009b70229598c6a80eef8b45bf282b-imagettftext.png" alt="Affichage de l'exemple : 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>: <span class="simpara">Cette fonction n&#039;est disponible que si
    si PHP est compilé avec le support Freetype (<strong class="option configure">--with-freetype-dir=DIR</strong>)
</span></p></blockquote>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.imagettftext-seealso">
  <h3 class="title">Voir aussi</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.imagettfbbox.php" class="function" rel="rdfs-seeAlso">imagettfbbox()</a> - Retourne le rectangle entourant un texte et dessin&eacute; avec une police TrueType</span></li>
   <li><span class="function"><a href="function.imagefttext.php" class="function" rel="rdfs-seeAlso">imagefttext()</a> - &Eacute;crit du texte dans une image avec la police courante FreeType 2</span></li>
   <li><span class="function"><a href="function.imagestring.php" class="function" rel="rdfs-seeAlso">imagestring()</a> - Dessine une cha&icirc;ne horizontale</span></li>
  </ul>
 </div>

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