<?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.getimagesize.php',
    1 => 'getimagesize',
    2 => 'Retourne la taille d\'une image',
  ),
  'up' => 
  array (
    0 => 'ref.image.php',
    1 => 'Fonctions GD et images',
  ),
  'prev' => 
  array (
    0 => 'function.gd-info.php',
    1 => 'gd_info',
  ),
  'next' => 
  array (
    0 => 'function.getimagesizefromstring.php',
    1 => 'getimagesizefromstring',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/image/functions/getimagesize.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.getimagesize" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">getimagesize</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">getimagesize</span> &mdash; <span class="dc-title">Retourne la taille d&#039;une image</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.getimagesize-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>getimagesize</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$filename</code></span>, <span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter reference">&$image_info</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <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>getimagesize()</strong></span> détermine la taille de toute image supportée
   fournie et en retourne les dimensions, le type d&#039;image et une chaîne type
   <code class="literal">height/width</code> à placer dans une balise
   <abbr title="Hyper Text Markup Language">HTML</abbr> <code class="tag">IMG</code> normale
   et le type de contenu <abbr title="Hypertext Transfer Protocol">HTTP</abbr> correspondant.
  </p>
  <p class="para">
   <span class="function"><strong>getimagesize()</strong></span> peut également retourner plus d&#039;informations
   dans le paramètre <code class="parameter">image_info</code>.
  </p>
  
  <div class="caution"><strong class="caution">Attention</strong>
   <p class="para">
    Cette fonction s&#039;attend à ce que <code class="parameter">filename</code> soit un 
    fichier image valide. Si un fichier non image est fourni, il peut être 
    détecté de manière incorrecte en tant qu&#039;image et la fonction retourne
    avec succès, mais le tableau peut contenir des valeurs absurdes.
   </p>
   <p class="para">
    Il ne faut pas utiliser <span class="function"><strong>getimagesize()</strong></span> pour vérifier qu&#039;un
    fichier donné est une image valide. Il est préférable d&#039;utiliser à la place une solution prévue
    pour cela telle que l&#039;extension <a href="book.fileinfo.php" class="link">FileInfo</a>.
   </p>
  </div>
  
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    Il est à noter que JPC et JP2 sont capables d&#039;avoir des composants avec une
    profondeur de bit différente. Dans ce cas, la valeur de &quot;bits&quot; est la plus
    grande profondeur de bit rencontrée. De même, les fichiers JP2 disposent
    du support de <code class="literal">multiple JPEG 2000 codestreams</code>.
    Dans ce cas, <span class="function"><strong>getimagesize()</strong></span> retourne les valeurs
    pour le premier codestream rencontré à la racine du fichier.
   </span>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    Les informations sur les icônes sont récupérées depuis l&#039;icône possédant
    le plus haut débit.
   </span>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    Les images GIF consistant d&#039;un ou plusieurs cadres, où chaque cadre peut occuper
    uniquement une partie de l&#039;image. La taille de l&#039;image qui est rapportée par
    <span class="function"><strong>getimagesize()</strong></span> est la taille globale (lue depuis le descripteur logique de l&#039;écran).
   </span>
  </p></blockquote>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.getimagesize-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
       Ce paramètre spécifie le fichier dont l&#039;on veut récupérer
       les informations. Il peut être un fichier local ou (suivant
       la configuration), un fichier distant en utilisant un des 
       <a href="wrappers.php" class="link">flux supportés</a>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">image_info</code></dt>
     <dd>
      <p class="para">
       Ce paramètre optionnel permet d&#039;extraire des informations
       supplémentaires du fichier image. Actuellement, cette option
       va retourner différents marqueurs <abbr>JPG</abbr>
       APP dans un tableau associatif. Certains programmes utilisent
       ces marqueurs APP pour préciser les informations dans les balises
       HTML. Un marqueur commun est le marqueur APP13, décrit
       à <a href="http://www.iptc.org/" class="link external">&raquo;&nbsp;IPTC</a>. Il est possible d&#039;utiliser
       la fonction <span class="function"><a href="function.iptcparse.php" class="function">iptcparse()</a></span> pour analyser ce marqueur,
       et obtenir des informations intelligibles.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        <code class="parameter">image_info</code> supporte uniquement
        les fichiers <abbr>JFIF</abbr>.
       </p>
      </p></blockquote>
     </dd>
    
   </dl>
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.getimagesize-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne un tableau contenant jusqu&#039;à 7 éléments. Tous les types
   d&#039;images n&#039;incluent pas les éléments <code class="literal">channels</code> et
   <code class="literal">bits</code>.
  </p>
  <p class="para">
   L&#039;index 0 contient la largeur. L&#039;index 1 contient la hauteur.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Certains formats peuvent ne contenir aucune image, ou bien plusieurs.
    Dans ces cas-là, <span class="function"><strong>getimagesize()</strong></span> peut ne pas être capable
    de déterminer correctement la taille de l&#039;image.
    <span class="function"><strong>getimagesize()</strong></span> retourne alors zéro comme taille de
    hauteur et largeur.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <span class="simpara">
    <span class="function"><strong>getimagesize()</strong></span> est indépendante des métadonnées de l&#039;image.
    Par exemple, si le drapeau Exif <code class="literal">Orientation</code> est défini sur une valeur qui
    fait pivoter l&#039;image de 90 ou 270 degrés, les indices 0 et 1 sont échangés,
    c&#039;est-à-dire qu&#039;ils contiennent respectivement la hauteur et la largeur.
</span>
  </p></blockquote>
  <p class="para">
   L&#039;index 2 est une constante parmi <strong><code><a href="image.constants.php#constant.imagetype-gif">IMAGETYPE_<span class="replaceable">*</span></a></code></strong>,
   indiquant le type de l&#039;image.
  </p>
  <p class="para">
   L&#039;index 3 contient la chaîne à placer dans les balises
   <abbr>IMG</abbr> : <code class="literal">height=&quot;xxx&quot; width=&quot;yyy&quot;</code>.
  </p>
  <p class="para">
   <code class="literal">mime</code> correspond au type MIME d&#039;une image.
   Cette information peut être utilisée pour envoyer l&#039;en-tête
   HTTP <code class="literal">Content-type</code> correct :
   <div class="example" id="example-1">
    <p><strong>Exemple #1 <span class="function"><strong>getimagesize()</strong></span> et types MIME</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$size </span><span style="color: #007700">= </span><span style="color: #0000BB">getimagesize</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">, </span><span style="color: #DD0000">"rb"</span><span style="color: #007700">);<br />if (</span><span style="color: #0000BB">$size </span><span style="color: #007700">&amp;&amp; </span><span style="color: #0000BB">$fp</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-type: </span><span style="color: #007700">{</span><span style="color: #0000BB">$size</span><span style="color: #007700">[</span><span style="color: #DD0000">'mime'</span><span style="color: #007700">]}</span><span style="color: #DD0000">"</span><span style="color: #007700">);<br />    </span><span style="color: #0000BB">fpassthru</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br />    exit;<br />} else {<br />    </span><span style="color: #FF8000">// error<br /></span><span style="color: #007700">}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <code class="literal">channels</code> sera 3 pour des images RGB et 4 pour
   des images CMYK.
  </p>
  <p class="para">
   <code class="literal">bits</code> est le nombre de bits pour chaque couleur.
  </p>
  <p class="para">
   Cependant, la présence des valeurs de <code class="literal">channels</code> et
   de <code class="literal">bits</code> peut mener à la confusion. Par
   exemple, une image <abbr title="Graphic Interchange Format">GIF</abbr> utilise toujours trois canaux par
   pixel, mais le nombre de bits par pixel ne peut être calculé dans le cas
   d&#039;une image animée <abbr title="Graphic Interchange Format">GIF</abbr> ayant une table de couleur
   globale.
  </p>
  <p class="para">
   Si une erreur survient, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> est retourné.
  </p>
 </div>

 <div class="refsect1 errors" id="refsect1-function.getimagesize-errors">
  <h3 class="title">Erreurs / Exceptions</h3>
  <p class="para">
   Si l&#039;accès à <code class="parameter">filename</code> est impossible,
   <span class="function"><strong>getimagesize()</strong></span> générera une erreur de niveau
   <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>. Si une erreur survient lors de la lecture,
   <span class="function"><strong>getimagesize()</strong></span> générera une erreur de niveau
   <strong><code><a href="errorfunc.constants.php#constant.e-notice">E_NOTICE</a></code></strong>.
  </p>
  <p class="para">
   À partir de PHP 8.0.0, une <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> est lancée
   si <code class="parameter">filename</code> est vide.
  </p>
 </div>

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

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.2.0</td>
       <td>
        Retourne les dimensions actuelles de l&#039;image, bits et chaînes des images AVIF;
        précédemment, les dimensions étaient reportées en tant que <code class="literal">0x0</code>,
        et bits et chaînes n&#039;étaient pas reportées du tout.
       </td>
      </tr>

      <tr>
       <td>8.0.0</td>
       <td>
        Une <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span> est désormais lancée si
        <code class="parameter">filename</code> est vide ; précédemment un
        <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> était émis et la fonction retournait <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
       </td>
      </tr>

      <tr>
       <td>7.1.0</td>
       <td>
        Ajout du support de WebP.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.getimagesize-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Exemple #2 Exemple avec <span class="function"><strong>getimagesize()</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: #007700">list(</span><span style="color: #0000BB">$width</span><span style="color: #007700">, </span><span style="color: #0000BB">$height</span><span style="color: #007700">, </span><span style="color: #0000BB">$type</span><span style="color: #007700">, </span><span style="color: #0000BB">$attr</span><span style="color: #007700">) = </span><span style="color: #0000BB">getimagesize</span><span style="color: #007700">(</span><span style="color: #DD0000">"img/flag.jpg"</span><span style="color: #007700">);<br />echo </span><span style="color: #DD0000">"&lt;img src=\"img/flag.jpg\" </span><span style="color: #0000BB">$attr</span><span style="color: #DD0000"> alt=\"Exemple avec getimagesize()\" /&gt;"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
   <div class="example" id="example-3">
    <p><strong>Exemple #3 <span class="function"><strong>getimagesize()</strong></span> avec une URL</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$size </span><span style="color: #007700">= </span><span style="color: #0000BB">getimagesize</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://www.example.com/gifs/logo.gif"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Si le nom du fichier comporte des espaces, encodez-le !<br /></span><span style="color: #0000BB">$size </span><span style="color: #007700">= </span><span style="color: #0000BB">getimagesize</span><span style="color: #007700">(</span><span style="color: #DD0000">"http://www.example.com/gifs/lo%20go.gif"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
   <div class="example" id="example-4">
    <p><strong>Exemple #4 <span class="function"><strong>getimagesize()</strong></span> qui retourne IPTC</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$size </span><span style="color: #007700">= </span><span style="color: #0000BB">getimagesize</span><span style="color: #007700">(</span><span style="color: #DD0000">"testimg.jpg"</span><span style="color: #007700">, </span><span style="color: #0000BB">$info</span><span style="color: #007700">);<br />if (isset(</span><span style="color: #0000BB">$info</span><span style="color: #007700">[</span><span style="color: #DD0000">"APP13"</span><span style="color: #007700">])) {<br />    </span><span style="color: #0000BB">$iptc </span><span style="color: #007700">= </span><span style="color: #0000BB">iptcparse</span><span style="color: #007700">(</span><span style="color: #0000BB">$info</span><span style="color: #007700">[</span><span style="color: #DD0000">"APP13"</span><span style="color: #007700">]);<br />    </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$iptc</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

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

 
 <div class="refsect1 notes" id="refsect1-function.getimagesize-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para">Cette fonction ne nécessite pas la bibliothèque GD.</p></p></blockquote>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.getimagesize-seealso">
  <h3 class="title">Voir aussi</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.image-type-to-mime-type.php" class="function" rel="rdfs-seeAlso">image_type_to_mime_type()</a> - Lit le Mime-Type d'un type d'image</span></li>
   <li><span class="function"><a href="function.exif-imagetype.php" class="function" rel="rdfs-seeAlso">exif_imagetype()</a> - D&eacute;termine le type d'une image</span></li>
   <li><span class="function"><a href="function.exif-read-data.php" class="function" rel="rdfs-seeAlso">exif_read_data()</a> - Lit les en-t&ecirc;tes EXIF dans les images</span></li>
   <li><span class="function"><a href="function.exif-thumbnail.php" class="function" rel="rdfs-seeAlso">exif_thumbnail()</a> - R&eacute;cup&egrave;re la miniature d'une image</span></li>
   <li><span class="function"><a href="function.imagesx.php" class="function" rel="rdfs-seeAlso">imagesx()</a> - Retourne la largeur d'une image</span></li>
   <li><span class="function"><a href="function.imagesy.php" class="function" rel="rdfs-seeAlso">imagesy()</a> - Retourne la hauteur de l'image</span></li>
  </ul>
 </div>

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