EXIF (Exchangeable Image File Format)¶
EXIF is a standard for storing metadata in image files, particularly JPEG and TIFF. It embeds information such as camera settings, date and time, GPS coordinates, orientation, thumbnail images, and other technical details captured by cameras and smartphones.
PHP provides the exif extension, which offers functions to read and write EXIF data from image files. This is commonly used for:
Retrieving camera make and model
Reading image orientation for automatic rotation
Extracting GPS coordinates for geotagging
Accessing date/time the photo was taken
Reading thumbnail images embedded in EXIF data
The EXIF data is stored in the file header and does not affect image quality. It is a subset of the TIFF format and is defined by the JEIDA standard, the Japan Electronic Industry Development Association.
Common EXIF functions include exif_read_data(), exif_imagetype(), exif_thumbnail(), and exif_process_raw_data(). Note that EXIF data may contain sensitive information such as GPS location, which should be considered for privacy.
<?php
// Reading EXIF data from an image
$exif = exif_read_data('photo.jpg', 'COMPUTED', true);
if ($exif !== false) {
echo 'Camera: ' . $exif['Make'] . ' ' . $exif['Model'] . "\n";
echo 'Date: ' . $exif['DateTimeOriginal'] . "\n";
echo 'Width: ' . $exif['COMPUTED']['Width'] . "\n";
echo 'Height: ' . $exif['COMPUTED']['Height'] . "\n";
}
// Check image type by EXIF data
$type = exif_imagetype('photo.jpg');
if ($type === IMAGETYPE_JPEG) {
echo 'This is a JPEG image';
}
?>
See also PHP EXIF functions and EXIF standard.
Related : Graphic Draw (GD), imagick, File, Image, Metadata, Privacy, Steganography, Security, Text Encoding