The Exif/IFD0 functions in PHP work with images to pull out meta data associated with them. Most image applications and digital cameras will produce an image with a certain amount of meta data present. This is obvious stuff like file size and creation time stamps, but you can also get stuff like copy right notices, camera name, date picture taken and even things like location if the camera was linked to a GPS system. This meta data can be used to sort or categorise images.
On Linux systems you must configure exif support with the command --enable-exif when calling the configure script.
On Windows all you have to do is uncomment the lines in your php.ini file for the DLL's php_exif.dll and php_mbstring.dll. However, you must ensure that the php_mbstring.dll DLL is loaded before the php_exif.dll DLL. So you will need to edit your php.ini file so that php_mbstring.dll is located above php_exif.dll.
To read the meta data from an image use the function exif_read_data(). This has various inputs but to print off a list of the different meta data available use the following code.
- $exif = exif_read_data('Picture0218.jpg', 0, true); // capture image meta data
- echo "Picture0218.jpg";
- echo '
This will print off a table containing all of the meta data available to PHP. To access an individual component you can access it through an associative array. The following code will print off the date and time that a picture was taken.
It is also possible to retrieve thumbnail information from the image (if the image contains it) by using the exif_read_data() function with the following parameters.
$exif = exif_read_data('Picture0218.jpg', 0, true, true);
You can pick out the thumbnail information using this:
$image = $exif['THUMBNAIL']['THUMBNAIL'];
Alternatively, you could use the exif_thumbnail() function which is a handy way of getting the thumbnail of any image. It takes the image name as the first parameter and three optional parameters which are set by the function.
You can then use the $width, $height and $type variables later on in your script.