Sophie

Sophie

distrib > Mageia > 7 > armv7hl > by-pkgid > 2b917e0437961edec048f1d15e2d7449 > files > 3320

php-manual-en-7.2.11-1.mga7.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>Reads the EXIF headers from an image file</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.exif-imagetype.html">exif_imagetype</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.exif-tagname.html">exif_tagname</a></div>
 <div class="up"><a href="ref.exif.html">Exif Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.exif-read-data" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">exif_read_data</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">exif_read_data</span> &mdash; <span class="dc-title">Reads the <acronym title="Exchangeable Image File ">EXIF</acronym> headers from an image file</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.exif-read-data-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">array</span> <span class="methodname"><strong>exif_read_data</strong></span>
    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$stream</code></span>
   [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$sections</code><span class="initializer"> = <strong><code>NULL</code></strong></span></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$arrays</code><span class="initializer"> = <strong><code>FALSE</code></strong></span></span>
   [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$thumbnail</code><span class="initializer"> = <strong><code>FALSE</code></strong></span></span>
  ]]] )</div>

  <p class="para rdfs-comment">
   <span class="function"><strong>exif_read_data()</strong></span> reads the
   <acronym title="Exchangeable Image File ">EXIF</acronym> headers from an image file. This way you can read meta data 
   generated by digital cameras.
  </p>
  <p class="para">
   <acronym title="Exchangeable Image File ">EXIF</acronym> headers tend to be present in JPEG/TIFF images generated by digital
   cameras, but unfortunately each digital camera maker has a different
   idea of how to actually tag their images, so you can&#039;t always rely on
   a specific Exif header being present.
  </p>
  <p class="para">
   <em>Height</em> and <em>Width</em> are computed the 
   same way <span class="function"><a href="function.getimagesize.html" class="function">getimagesize()</a></span> does so their values must not be 
   part of any header returned.  Also, <em>html</em> is a 
   height/width text string to be used inside normal <acronym title="Hyper Text Markup Language">HTML</acronym>.
  </p>
  <p class="para">
   When an Exif header contains a Copyright note, this itself can contain two
   values. As the solution is inconsistent in the Exif 2.10 standard, the
   <em>COMPUTED</em> section will return both entries
   <em>Copyright.Photographer</em> and
   <em>Copyright.Editor</em> while the <em>IFD0</em>
   sections contains the byte array with the NULL character that splits both
   entries. Or just the first entry if the datatype was wrong (normal behaviour
   of Exif). The <em>COMPUTED</em> will also contain the entry
   <em>Copyright</em> which is either the original copyright string,
   or a comma separated list of the photo and editor copyright.
  </p>
  <p class="para">
   The tag <em>UserComment</em> has the same problem as the Copyright
   tag. It can store two values.  First the encoding used, and second the value
   itself. If so the <em>IFD</em> section only contains the encoding
   or a byte array. The <em>COMPUTED</em> section will store both in
   the entries <em>UserCommentEncoding</em> and
   <em>UserComment</em>. The entry <em>UserComment</em>
   is available in both cases so it should be used in preference to the value
   in <em>IFD0</em> section.
  </p>
  <p class="para">
   <span class="function"><strong>exif_read_data()</strong></span> also validates EXIF data tags according
   to the EXIF specification (<a href="http://exif.org/Exif2-2.PDF" class="link external">&raquo;&nbsp;http://exif.org/Exif2-2.PDF</a>, page 20).
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Windows Me/XP can both wipe the Exif headers when connecting to a camera.
   </p>
  </p></blockquote>
 </div>

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

    
     <dt>
<code class="parameter">stream</code></dt>

     <dd>

      <p class="para">
       The location of the image file. This can either be a path to the file
       (stream wrappers are also supported as usual)
       or a stream <span class="type"><a href="language.types.resource.html" class="type resource">resource</a></span>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">sections</code></dt>

     <dd>

      <p class="para">
       Is a comma separated list of sections that need to be present in file 
       to produce a result <span class="type"><a href="language.types.array.html" class="type array">array</a></span>.  If none of the requested 
       sections could be found the return value is <strong><code>FALSE</code></strong>.
       <table class="doctable informaltable">
        
         <tbody class="tbody">
          <tr>
           <td>FILE</td>
           <td>FileName, FileSize, FileDateTime, SectionsFound</td>
          </tr>

          <tr>
           <td>COMPUTED</td>
           <td>
            html, Width, Height, IsColor, and more if available.  Height and 
            Width are computed the same way <span class="function"><a href="function.getimagesize.html" class="function">getimagesize()</a></span>
            does so their values must not be part of any header returned. 
            Also, <em>html</em> is a height/width text string to be used inside normal 
            <acronym title="Hyper Text Markup Language">HTML</acronym>.
           </td>
          </tr>

          <tr>
           <td>ANY_TAG</td>
           <td>Any information that has a Tag e.g. <em>IFD0</em>, <em>EXIF</em>, ...</td>
          </tr>

          <tr>
           <td>IFD0</td>
           <td>
            All tagged data of IFD0. In normal imagefiles this contains
            image size and so forth.
           </td>
          </tr>

          <tr>
           <td>THUMBNAIL</td>
           <td>
            A file is supposed to contain a thumbnail if it has a second <em>IFD</em>.
            All tagged information about the embedded thumbnail is stored in 
            this section.
           </td>
          </tr>

          <tr>
           <td>COMMENT</td>
           <td>Comment headers of JPEG images.</td>
          </tr>

          <tr>
           <td>EXIF</td>
           <td>
            The EXIF section is a sub section of <em>IFD0</em>. It contains
            more detailed information about an image. Most of these entries
            are digital camera related.
           </td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>

    
    
     <dt>
<code class="parameter">arrays</code></dt>

      <dd>

      <p class="para">
       Specifies whether or not each section becomes an array. The 
       <code class="parameter">sections</code> <em>COMPUTED</em>,
       <em>THUMBNAIL</em>, and <em>COMMENT</em> 
       always become arrays as they may contain values whose names conflict
       with other sections.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">thumbnail</code></dt>

     <dd>

      <p class="para">
       When set to <strong><code>TRUE</code></strong> the thumbnail itself is read.  Otherwise, only the
       tagged data is read.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>
    
 <div class="refsect1 returnvalues" id="refsect1-function.exif-read-data-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   It returns an associative <span class="type"><a href="language.types.array.html" class="type array">array</a></span> where the array indexes are 
   the header names and the array values are the values associated with 
   those headers. If no data can be returned, 
   <span class="function"><strong>exif_read_data()</strong></span> will return <strong><code>FALSE</code></strong>.
  </p>
 </div>

 <div class="refsect1 changelog" id="refsect1-function.exif-read-data-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>7.2.0</td>
       <td>
        The <code class="parameter">filename</code> parameter was renamed to 
        <code class="parameter">stream</code> and now supports both local files 
        or stream resources.
       </td>
      </tr>

      <tr>
       <td>7.2.0</td>
       <td>
        Support for the following EXIF formats were added:
       <ul class="itemizedlist">
        <li class="listitem">
         <span class="simpara">
          Samsung
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          DJI
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          Panasonic
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          Sony
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          Pentax
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          Minolta
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          Sigma/Foveon
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          AGFA
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          Kyocera
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          Ricoh
         </span>
        </li>
        <li class="listitem">
         <span class="simpara">
          Epson
         </span>
        </li>
       </ul>
       </td>
      </tr>

      <tr>
       <td>4.3.0</td>
       <td>
        Can read all embedded <acronym title="Image File Directory">IFD</acronym> data including arrays 
        (returned as such). Also the size of an embedded thumbnail is 
        returned in a <em>THUMBNAIL</em> subarray, and can 
        return thumbnails in <acronym title="Tagged Image File Format">TIFF</acronym> format.  Also, there is 
        no longer a maximum length for returned values (not until the memory 
        limit has been reached).
       </td>
      </tr>

      <tr>
       <td>4.3.0</td>
       <td>
        If PHP has  <a href="ref.mbstring.html" class="link">mbstring</a> support,
        the user comment can automatically change encoding.  Also, if the
        user comment uses <em>Unicode</em> or <em>JIS</em> encoding this encoding will 
        automatically be changed according to the exif ini settings in 
        <var class="filename">php.ini</var>
       </td>
      </tr>

      <tr>
       <td>4.3.0</td>
       <td>
        If the image contains any <em>IFD0</em> data then
        <em>COMPUTED</em> contains the entry
        <em>ByteOrderMotorola</em> which is 0 for
        <em>little-endian</em> (intel) and 1 for
        <em>big-endian</em> (motorola) byte order.  Also,
        <em>COMPUTED</em> and <em>UserComment</em> no 
        longer only contain the first copyright entry if the datatype was 
        wrong.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.exif-read-data-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-3722">
    <p><strong>Example #1 <span class="function"><strong>exif_read_data()</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">echo&nbsp;</span><span style="color: #DD0000">"test1.jpg:&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$exif&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">exif_read_data</span><span style="color: #007700">(</span><span style="color: #DD0000">'tests/test1.jpg'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'IFD0'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$exif</span><span style="color: #007700">===</span><span style="color: #0000BB">false&nbsp;</span><span style="color: #007700">?&nbsp;</span><span style="color: #DD0000">"No&nbsp;header&nbsp;data&nbsp;found.&lt;br&nbsp;/&gt;\n"&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">"Image&nbsp;contains&nbsp;headers&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$exif&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">exif_read_data</span><span style="color: #007700">(</span><span style="color: #DD0000">'tests/test2.jpg'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #DD0000">"test2.jpg:&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />foreach&nbsp;(</span><span style="color: #0000BB">$exif&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$key&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$section</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$section&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$name&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$val</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$key</span><span style="color: #DD0000">.</span><span style="color: #0000BB">$name</span><span style="color: #DD0000">:&nbsp;</span><span style="color: #0000BB">$val</span><span style="color: #DD0000">&lt;br&nbsp;/&gt;\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>
     The first call fails because the image has no header information.
    </p></div>
    <div class="example-contents"><p>The above example will output
something similar to:</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
test1.jpg:
No header data found.
test2.jpg:
FILE.FileName: test2.jpg
FILE.FileDateTime: 1017666176
FILE.FileSize: 1240
FILE.FileType: 2
FILE.SectionsFound: ANY_TAG, IFD0, THUMBNAIL, COMMENT
COMPUTED.html: width=&quot;1&quot; height=&quot;1&quot;
COMPUTED.Height: 1
COMPUTED.Width: 1
COMPUTED.IsColor: 1
COMPUTED.ByteOrderMotorola: 1
COMPUTED.UserComment: Exif test image.
COMPUTED.UserCommentEncoding: ASCII
COMPUTED.Copyright: Photo (c) M.Boerger, Edited by M.Boerger.
COMPUTED.Copyright.Photographer: Photo (c) M.Boerger
COMPUTED.Copyright.Editor: Edited by M.Boerger.
IFD0.Copyright: Photo (c) M.Boerger
IFD0.UserComment: ASCII
THUMBNAIL.JPEGInterchangeFormat: 134
THUMBNAIL.JPEGInterchangeFormatLength: 523
COMMENT.0: Comment #1.
COMMENT.1: Comment #2.
COMMENT.2: Comment #3end
THUMBNAIL.JPEGInterchangeFormat: 134
THUMBNAIL.Thumbnail.Height: 1
THUMBNAIL.Thumbnail.Height: 1
</pre></div>
    </div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-3723">
    <p><strong>Example #2 <span class="function"><strong>exif_read_data()</strong></span> with streams available as of PHP 7.2.0</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">//&nbsp;Open&nbsp;a&nbsp;the&nbsp;file,&nbsp;this&nbsp;should&nbsp;be&nbsp;in&nbsp;binary&nbsp;mode<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'/path/to/image.jpg'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'rb'</span><span style="color: #007700">);<br /><br />if&nbsp;(!</span><span style="color: #0000BB">$fp</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Error:&nbsp;Unable&nbsp;to&nbsp;open&nbsp;image&nbsp;for&nbsp;reading'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Attempt&nbsp;to&nbsp;read&nbsp;the&nbsp;exif&nbsp;headers<br /></span><span style="color: #0000BB">$headers&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">exif_read_data</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /><br />if&nbsp;(!</span><span style="color: #0000BB">$headers</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Error:&nbsp;Unable&nbsp;to&nbsp;read&nbsp;exif&nbsp;headers'</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Print&nbsp;the&nbsp;'COMPUTED'&nbsp;headers<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'EXIF&nbsp;Headers:'&nbsp;</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">;<br /><br />foreach&nbsp;(</span><span style="color: #0000BB">$headers</span><span style="color: #007700">[</span><span style="color: #DD0000">'COMPUTED'</span><span style="color: #007700">]&nbsp;as&nbsp;</span><span style="color: #0000BB">$header&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">'&nbsp;%s&nbsp;=&gt;&nbsp;%s%s'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$header</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">PHP_EOL</span><span style="color: #007700">);<br />}<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="example-contents screen">
<div class="cdata"><pre>
EXIF Headers:
 Height =&gt; 576
 Width =&gt; 1024
 IsColor =&gt; 1
 ByteOrderMotorola =&gt; 0
 ApertureFNumber =&gt; f/5.6
 UserComment =&gt;
 UserCommentEncoding =&gt; UNDEFINED
 Copyright =&gt; Denis
 Thumbnail.FileType =&gt; 2
 Thumbnail.MimeType =&gt; image/jpeg
</pre></div>
    </div>
   </div>
  </p>
 </div>

 <div class="refsect1 notes" id="refsect1-function.exif-read-data-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    If <a href="ref.mbstring.html" class="link">mbstring</a> is enabled, exif will attempt to process 
    the unicode and pick a charset as specified by 
    <a href="exif.configuration.html#ini.exif.decode-unicode-motorola" class="link">exif.decode_unicode_motorola</a> and 
    <a href="exif.configuration.html#ini.exif.decode-unicode-intel" class="link">exif.decode_unicode_intel</a>. The exif 
    extension will not attempt to figure out the encoding on its own, and it is up to the user 
    to properly specify the encoding for which to use for decoding by setting one of these two 
    ini directives prior to calling <span class="function"><strong>exif_read_data()</strong></span>. 
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    If the <code class="parameter">stream</code> is used to pass a stream to this function, then the stream 
    must be seekable. Note that the file pointer position is not changed after this function returns.
   </p>
  </p></blockquote>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.exif-read-data-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.exif-thumbnail.html" class="function" rel="rdfs-seeAlso">exif_thumbnail()</a> - Retrieve the embedded thumbnail of an image</span></li>
    <li class="member"><span class="function"><a href="function.getimagesize.html" class="function" rel="rdfs-seeAlso">getimagesize()</a> - Get the size of an image</span></li>
    <li class="member"><a href="wrappers.html" class="xref">Supported Protocols and Wrappers</a></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.exif-imagetype.html">exif_imagetype</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.exif-tagname.html">exif_tagname</a></div>
 <div class="up"><a href="ref.exif.html">Exif Functions</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>