exif_imagetype
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
exif_imagetype — Determine the type of an image
Description
$filename
) : intexif_imagetype() reads the first bytes of an image and checks its signature.
exif_imagetype() can be used to avoid calls to other exif functions with unsupported file types or in conjunction with $_SERVER['HTTP_ACCEPT'] to check whether or not the viewer is able to see a specific image in the browser.
Return Values
When a correct signature is found, the appropriate constant value will be
returned otherwise the return value is FALSE
. The return value is the
same value that getimagesize() returns in index 2 but
exif_imagetype() is much faster.
Note:
exif_imagetype() will emit an
E_NOTICE
and returnFALSE
if it is unable to read enough bytes from the file to determine the image type.
Predefined Constants
The following constants are defined, and represent possible exif_imagetype() return values:
Value | Constant |
---|---|
1 | IMAGETYPE_GIF |
2 | IMAGETYPE_JPEG |
3 | IMAGETYPE_PNG |
4 | IMAGETYPE_SWF |
5 | IMAGETYPE_PSD |
6 | IMAGETYPE_BMP |
7 | IMAGETYPE_TIFF_II (intel byte order) |
8 |
IMAGETYPE_TIFF_MM (motorola byte order)
|
9 | IMAGETYPE_JPC |
10 | IMAGETYPE_JP2 |
11 | IMAGETYPE_JPX |
12 | IMAGETYPE_JB2 |
13 | IMAGETYPE_SWC |
14 | IMAGETYPE_IFF |
15 | IMAGETYPE_WBMP |
16 | IMAGETYPE_XBM |
17 | IMAGETYPE_ICO |
18 | IMAGETYPE_WEBP |
Examples
Example #1 exif_imagetype() example
<?php
if (exif_imagetype('image.gif') != IMAGETYPE_GIF) {
echo 'The picture is not a gif';
}
?>
See Also
- image_type_to_mime_type() - Get Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype
- getimagesize() - Get the size of an image
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-function.exif-imagetype.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.