An EXIF (Exchangeable Image File Format) is a metadata type storage that provides specific information about media files, in this case photographs (it also exists for sound and video), such as camera settings, time, date, location (GPS) and technical characteristics of the image and camera. This information is written to the image file itself.
This data is used by the camera (or smartphone) for cataloging (by date, type, location, among others) but also by media management systems and applications to provide information about the files.
Obtaining exif data from images with PHP is done with the function exif_read_data():
$exif = exif_read_data($image, 0, true);
Creating a function that provides the main information:
function getExifImage($image) {
$exif = exif_read_data($image, 0, true);
// Focal Length
$focal_length = $exif["EXIF"]["FocalLength"];
$lens = $exif["EXIF"]["UndefinedTag:0xA434"];
$focal_calc = eval('return ' . $focal_length . ';');
return [
'brand' => $exif["IFD0"]["Make"],
'model' => $exif["IFD0"]["Model"],
'type' => $exif["FILE"]["MimeType"],
'date' => date('Y-m-d H:i:s', $exif["FILE"]["FileDateTime"]),
'dimensions' => $exif["COMPUTED"]["Width"].' x '.$exif["COMPUTED"]["Height"],
'aperture' => $exif["COMPUTED"]["ApertureFNumber"],
'focallength' => "$focal_calc mm"
];
}
How to access EXIF information (for common user)?
On Windows, right-click the image file and click Properties > Details.
On MacOS, open the photo and go to Tools > Show Inspector.