<?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 => 'uk',
  ),
  'this' => 
  array (
    0 => 'function.getimagesize.php',
    1 => 'getimagesize',
    2 => 'Get the size of an image',
  ),
  'up' => 
  array (
    0 => 'ref.image.php',
    1 => 'Функції GD та Image',
  ),
  'prev' => 
  array (
    0 => 'function.gd-info.php',
    1 => 'gd_info',
  ),
  'next' => 
  array (
    0 => 'function.getimagesizefromstring.php',
    1 => 'getimagesizefromstring',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    '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">Get the size of an image</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.getimagesize-description">
  <h3 class="title">Опис</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">
   The <span class="function"><strong>getimagesize()</strong></span> function will determine the
   size of any supported given image file and return the dimensions along with
   the file type and a <code class="literal">height/width</code> text string to be used inside a
   normal <abbr title="Hyper Text Markup Language">HTML</abbr> <code class="tag">IMG</code> tag and the
   correspondent <abbr title="Hypertext Transfer Protocol">HTTP</abbr> content type.
  </p>
  <p class="para">
   <span class="function"><strong>getimagesize()</strong></span> can also return some more information
   in <code class="parameter">image_info</code> parameter.
  </p>
  <div class="caution"><strong class="caution">Застереження</strong>
   <p class="para">
    This function expects <code class="parameter">filename</code> to be a valid
    image file. If a non-image file is supplied, it may be incorrectly
    detected as an image and the function will return successfully, but
    the array may contain nonsensical values.
   </p>
   <p class="para">
    Do not use <span class="function"><strong>getimagesize()</strong></span> to check that a given
    file is a valid image. Use a purpose-built solution such as the
    <a href="book.fileinfo.php" class="link">Fileinfo</a> extension instead.
   </p>
  </div>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <span class="simpara">
    Note that JPC and JP2 are capable of having components with different 
    bit depths. In this case, the value for &quot;bits&quot; is the highest bit depth encountered. Also, JP2
    files may contain <code class="literal">multiple JPEG 2000 codestreams</code>. In this case,
    <span class="function"><strong>getimagesize()</strong></span> returns the values for the first
    codestream it encounters in the root of the file.
   </span>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <span class="simpara">
    The information about icons are retrieved from the icon with the highest
    bitrate.
   </span>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <span class="simpara">
    GIF images consist of one or more frames, where each frame may only occupy
    part of the image. The size of the image which is reported by
    <span class="function"><strong>getimagesize()</strong></span> is the overall size (read from the logical
    screen descriptor).
   </span>
  </p></blockquote>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.getimagesize-parameters">
  <h3 class="title">Параметри</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">filename</code></dt>
     <dd>
      <p class="para">
        This parameter specifies the file you wish to retrieve information
        about. It can reference a local file or (configuration permitting) a
        remote file using one of the <a href="wrappers.php" class="link">supported streams</a>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">image_info</code></dt>
     <dd>
      <p class="para">
       This optional parameter allows you to extract some extended
       information from the image file. Currently, this will return the
       different <abbr>JPG</abbr> APP markers as an associative array.
       Some programs use these APP markers to embed text information in 
       images. A very common one is to embed 
       <a href="http://www.iptc.org/" class="link external">&raquo;&nbsp;IPTC</a> information in the APP13 marker.
       You can use the <span class="function"><a href="function.iptcparse.php" class="function">iptcparse()</a></span> function to parse the
       binary APP13 marker into something readable.
      </p>
      <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
       <p class="para">
        The <code class="parameter">image_info</code> only supports
        <abbr>JFIF</abbr> files.
       </p>
      </p></blockquote>
     </dd>
    
   </dl>
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.getimagesize-returnvalues">
  <h3 class="title">Значення, що повертаються</h3>
  <p class="para">
   Returns an array with up to 7 elements. Not all image types will include
   the <code class="literal">channels</code> and <code class="literal">bits</code> elements.
  </p>
  <p class="para">
   Index 0 and 1 contains respectively the width and the height of the image.
  </p>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <p class="para">
    Some formats may contain no image or may contain multiple images. In these
    cases, <span class="function"><strong>getimagesize()</strong></span> might not be able to properly
    determine the image size. <span class="function"><strong>getimagesize()</strong></span> will return
    zero for width and height in these cases.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: 
   <span class="simpara">
    <span class="function"><strong>getimagesize()</strong></span> is agnostic of any image metadata.
    If e.g. the Exif <code class="literal">Orientation</code> flag is set to a value which
    rotates the image by 90 or 270 degress, index 0 and 1 are swapped,
    i.e. the contain the height and width, respectively.
   </span>
  </p></blockquote>
  <p class="para">
   Index 2 is one of the <strong><code><a href="image.constants.php#constant.imagetype-gif">IMAGETYPE_<span class="replaceable">*</span></a></code></strong> constants indicating
   the type of the image.
  </p>
  <p class="para">
   Index 3 is a text string with the correct 
   <code class="literal">height=&quot;yyy&quot; width=&quot;xxx&quot;</code> string that can be used
   directly in an <abbr>IMG</abbr> tag.
  </p>
  <p class="para">
   <code class="literal">mime</code> is the correspondant MIME type of the image.
   This information can be used to deliver images with the correct HTTP 
   <code class="literal">Content-type</code> header:
   <div class="example" id="example-1">
    <p><strong>Приклад #1 <span class="function"><strong>getimagesize()</strong></span> and MIME types</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> will be 3 for RGB pictures and 4 for CMYK
   pictures.
  </p>
  <p class="para">
   <code class="literal">bits</code> is the number of bits for each color.
  </p>
  <p class="para">
   For some image types, the presence of <code class="literal">channels</code> and
   <code class="literal">bits</code> values can be a bit
   confusing. As an example, <abbr title="Graphic Interchange Format">GIF</abbr> always uses 3 channels
   per pixel, but the number of bits per pixel cannot be calculated for an
   animated <abbr title="Graphic Interchange Format">GIF</abbr> with a global color 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 errors" id="refsect1-function.getimagesize-errors">
  <h3 class="title">Помилки/виключення</h3>
  <p class="para">
   If accessing the <code class="parameter">filename</code> image is impossible
   <span class="function"><strong>getimagesize()</strong></span> will generate an error of level
   <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>. On read error,
   <span class="function"><strong>getimagesize()</strong></span> will generate an error of level
   <strong><code><a href="errorfunc.constants.php#constant.e-notice">E_NOTICE</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.getimagesize-changelog">
  <h3 class="title">Журнал змін</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Версія</th>
       <th>Опис</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.2.0</td>
       <td>
        Now returns the actual image dimensions, bits and channels of AVIF images;
        previously, the dimensions were reported as <code class="literal">0x0</code>,
        and bits and channels were not reported at all.
       </td>
      </tr>

      <tr>
       <td>7.1.0</td>
       <td>
        Added WebP support.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.getimagesize-examples">
  <h3 class="title">Приклади</h3>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Приклад #2 <span class="function"><strong>getimagesize()</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: #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=\"getimagesize() example\" /&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>Приклад #3 getimagesize (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">// if the file name has space in it, encode it properly<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>Приклад #4 getimagesize() returning 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">Примітки</h3>
  <blockquote class="note"><p><strong class="note">Зауваження</strong>: <p class="para">Ця функція не потребує
бібліотеки зображень GD.</p></p></blockquote>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.getimagesize-seealso">
  <h3 class="title">Прогляньте також</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> - Get Mime-Type for image-type returned by getimagesize,
   exif_read_data, exif_thumbnail, exif_imagetype</span></li>
   <li><span class="function"><a href="function.exif-imagetype.php" class="function" rel="rdfs-seeAlso">exif_imagetype()</a> - Determine the type of an image</span></li>
   <li><span class="function"><a href="function.exif-read-data.php" class="function" rel="rdfs-seeAlso">exif_read_data()</a> - Reads the EXIF headers from an image file</span></li>
   <li><span class="function"><a href="function.exif-thumbnail.php" class="function" rel="rdfs-seeAlso">exif_thumbnail()</a> - Retrieve the embedded thumbnail of an image</span></li>
   <li><span class="function"><a href="function.imagesx.php" class="function" rel="rdfs-seeAlso">imagesx()</a> - Get image width</span></li>
   <li><span class="function"><a href="function.imagesy.php" class="function" rel="rdfs-seeAlso">imagesy()</a> - Get image height</span></li>
  </ul>
 </div>

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