Tag Archives: exif

Reading Exif data with PHP

Within most photos from digital cameras besides the actual image, there’s a little ”information block” call EXIF data. If you have the correct PHP extension installed on your server – the one called ”exif” – it’s pretty easy to read the EXIF data and display them, as you like.

First, let’s check if the extension is available?

1
2
3
4
5
6
$load_ext = get_loaded_extensions();
if (!in_array(exif, $load_ext)) {
echo "Exif is NOT available";
} else {
echo "Exif extension is available.";
};

If you have the extension available, reading the data is a simple matter:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$nikonFile   = './aarhus_demo_photo.jpg';
$exifNikon   = getExifData($nikonFile);
 
$olympusFile = './zanzibar_demo_photo.jpg';
$exifOlympus = getExifData($olympusFile);
 
echo "<h2>Olympus EXIF data</h2>";
echo "<pre>";
print_r($exifOlympus);
echo "</pre>";
 
echo "<h2>Nikon EXIF data</h2>";
echo "<pre>";
print_r($exifNikon);
echo "</pre>";
 
function getExifData($file) {
$exif = exif_read_data($file, 0, true);
return $exif;
}

As you may notice, there’s a photo from an Olympus camera and a Nikon camera as an example. The data available from each photo isn’t quite the same. Most generic fields are available, but some fields are camera specific (or maker specific).

See the example above in action (source). The two images are from Aarhus (Nikon) and Zanzibar (Olympus). You can read more on EXIF in Wikipedia.