<!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>Determine the type of an image</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ref.exif.html">Exif Functions</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.exif-read-data.html">exif_read_data</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-imagetype" class="refentry"> <div class="refnamediv"> <h1 class="refname">exif_imagetype</h1> <p class="verinfo">(PHP 4 >= 4.3.0, PHP 5)</p><p class="refpurpose"><span class="refname">exif_imagetype</span> — <span class="dc-title">Determine the type of an image</span></p> </div> <div class="refsect1 description" id="refsect1-function.exif-imagetype-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><strong>exif_imagetype</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span> )</div> <p class="para rdfs-comment"> <span class="function"><strong>exif_imagetype()</strong></span> reads the first bytes of an image and checks its signature. </p> <p class="para"> <span class="function"><strong>exif_imagetype()</strong></span> can be used to avoid calls to other <a href="ref.exif.html" class="link">exif</a> functions with unsupported file types or in conjunction with <var class="varname"><var class="varname"><a href="reserved.variables.server.html" class="classname">$_SERVER['HTTP_ACCEPT']</a></var></var> to check whether or not the viewer is able to see a specific image in the browser. </p> </div> <div class="refsect1 parameters" id="refsect1-function.exif-imagetype-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">filename</code></em></span> <dd> <span class="simpara"> The image being checked. </span> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.exif-imagetype-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> When a correct signature is found, the appropriate constant value will be returned otherwise the return value is <strong><code>FALSE</code></strong>. The return value is the same value that <span class="function"><a href="function.getimagesize.html" class="function">getimagesize()</a></span> returns in index 2 but <span class="function"><strong>exif_imagetype()</strong></span> is much faster. </p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> <span class="function"><strong>exif_imagetype()</strong></span> will emit an <strong><code>E_NOTICE</code></strong> and return <strong><code>FALSE</code></strong> if it is unable to read enough bytes from the file to determine the image type. </p> </p></blockquote> </div> <div class="refsect1 changelog" id="refsect1-function.exif-imagetype-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>5.3.0</td> <td> Added icon support. </td> </tr> <tr> <td>4.3.2</td> <td> Support for <acronym title="Japan Picture">JPC</acronym>, <acronym title="JPEG-2000">JP2</acronym>, <acronym>JPX</acronym>, <acronym title="Joint Bilevel Image Experts Group">JB2</acronym>, <acronym title="X Bitmap">XBM</acronym>, and <acronym title="Wireless Bitmap">WBMP</acronym> </td> </tr> <tr> <td>4.3.0</td> <td>Support for <acronym>SWC</acronym></td> </tr> </tbody> </table> </p> </div> <div class="refsect1 constants" id="refsect1-function.exif-imagetype-constants"> <h3 class="title">Predefined Constants</h3> <p class="para"> The following constants are defined, and represent possible <span class="function"><strong>exif_imagetype()</strong></span> return values: <table class="doctable table"> <caption><strong>Imagetype Constants</strong></caption> <thead> <tr> <th>Value</th> <th>Constant</th> </tr> </thead> <tbody class="tbody"> <tr> <td>1</td> <td><strong><code>IMAGETYPE_GIF</code></strong></td> </tr> <tr> <td>2</td> <td><strong><code>IMAGETYPE_JPEG</code></strong></td> </tr> <tr> <td>3</td> <td><strong><code>IMAGETYPE_PNG</code></strong></td> </tr> <tr> <td>4</td> <td><strong><code>IMAGETYPE_SWF</code></strong></td> </tr> <tr> <td>5</td> <td><strong><code>IMAGETYPE_PSD</code></strong></td> </tr> <tr> <td>6</td> <td><strong><code>IMAGETYPE_BMP</code></strong></td> </tr> <tr> <td>7</td> <td><strong><code>IMAGETYPE_TIFF_II</code></strong> (intel byte order)</td> </tr> <tr> <td>8</td> <td> <strong><code>IMAGETYPE_TIFF_MM</code></strong> (motorola byte order) </td> </tr> <tr> <td>9</td> <td><strong><code>IMAGETYPE_JPC</code></strong></td> </tr> <tr> <td>10</td> <td><strong><code>IMAGETYPE_JP2</code></strong></td> </tr> <tr> <td>11</td> <td><strong><code>IMAGETYPE_JPX</code></strong></td> </tr> <tr> <td>12</td> <td><strong><code>IMAGETYPE_JB2</code></strong></td> </tr> <tr> <td>13</td> <td><strong><code>IMAGETYPE_SWC</code></strong></td> </tr> <tr> <td>14</td> <td><strong><code>IMAGETYPE_IFF</code></strong></td> </tr> <tr> <td>15</td> <td><strong><code>IMAGETYPE_WBMP</code></strong></td> </tr> <tr> <td>16</td> <td><strong><code>IMAGETYPE_XBM</code></strong></td> </tr> <tr> <td>17</td> <td><strong><code>IMAGETYPE_ICO</code></strong></td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.exif-imagetype-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-3162"> <p><strong>Example #1 <span class="function"><strong>exif_imagetype()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #007700">if (</span><span style="color: #0000BB">exif_imagetype</span><span style="color: #007700">(</span><span style="color: #DD0000">'image.gif'</span><span style="color: #007700">) != </span><span style="color: #0000BB">IMAGETYPE_GIF</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">'The picture is not a gif'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.exif-imagetype-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.image-type-to-mime-type.html" 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 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> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="ref.exif.html">Exif Functions</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.exif-read-data.html">exif_read_data</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>