PHP exif_read_data() function is used to get the detail information about a image like when the image taken, when last modified, what device used to take the picture, width/ height/ resolution of the image etc. Also it will provide the software name on which the image edited.

PHP Code to get Image Info

$filename = 'Photo130.jpg';
if (file_exists($filename)) {

$exif = exif_read_data($filename, 0, true);
  foreach ($exif as $key => $section) {
    foreach ($section as $name => $val) {
     echo "$key.$name: $val<br />\n";
    }
  }
}

Output

FILE.FileName: Photo130.jpg
FILE.FileDateTime: 1411384560
FILE.FileSize: 697559
FILE.FileType: 2
FILE.MimeType: image/jpeg
FILE.SectionsFound: ANY_TAG, IFD0, THUMBNAIL, EXIF, INTEROP
COMPUTED.html: width="956" height="1144"
COMPUTED.Height: 1144
COMPUTED.Width: 956
COMPUTED.IsColor: 1
COMPUTED.ByteOrderMotorola: 1
COMPUTED.ApertureFNumber: f/2.8
COMPUTED.UserComment: QCAM-AA
COMPUTED.Thumbnail.FileType: 2
COMPUTED.Thumbnail.MimeType: image/jpeg
IFD0.ImageWidth: 1280
IFD0.ImageLength: 960
IFD0.Make: SAMSUNG
IFD0.Model: SCH-S239
IFD0.Orientation: 1
IFD0.XResolution: 720000/10000
IFD0.YResolution: 720000/10000
IFD0.ResolutionUnit: 2
IFD0.Software: Adobe Photoshop CS3 Windows
IFD0.DateTime: 2014:09:22 16:45:58
IFD0.YCbCrPositioning: 1
IFD0.UndefinedTag:0xC4A5: PrintIM0300
IFD0.Exif_IFD_Pointer: 268
THUMBNAIL.Compression: 6
THUMBNAIL.XResolution: 72/1
THUMBNAIL.YResolution: 72/1
THUMBNAIL.ResolutionUnit: 2
THUMBNAIL.JPEGInterchangeFormat: 734
THUMBNAIL.JPEGInterchangeFormatLength: 7231
EXIF.ExposureTime: 5/1024
EXIF.FNumber: 28/10
EXIF.ISOSpeedRatings: 50
EXIF.ExifVersion: 0220
EXIF.DateTimeOriginal: 2013:06:08 17:08:51
EXIF.DateTimeDigitized: 2013:06:08 17:08:51
EXIF.ComponentsConfiguration: 
EXIF.MaxApertureValue: 297/100
EXIF.MeteringMode: 2
EXIF.FocalLength: 287/100
EXIF.UserComment: QCAM-AA
EXIF.ColorSpace: 1
EXIF.ExifImageWidth: 956
EXIF.ExifImageLength: 1144
EXIF.InteroperabilityOffset: 608
EXIF.ExposureMode: 0
EXIF.WhiteBalance: 0
EXIF.DigitalZoomRatio: 1/1
EXIF.SceneCaptureType: 3
INTEROP.InterOperabilityIndex: R98
INTEROP.InterOperabilityVersion: 0100


Use the following code to get specific information

$filename = 'Photo130.jpg';
if (file_exists($filename)) {
$exif = exif_read_data($filename, 0, true);
echo "File Name: ".$exif['FILE']['FileName']."<br>";
echo "File Size: ".$exif['FILE']['FileSize']."<br>";
echo "File Date Time: ".date ("F d Y H:i:s.",$exif['FILE']['FileDateTime']);
echo "File Mime Type: ".$exif['FILE']['MimeType']."<br>";
echo "Device Make: ".$exif['IFD0']['Make']."<br>";
echo "Device Model: ".$exif['IFD0']['Model']."<br>";
echo "Image Width: ".$exif['COMPUTED']['Width']."<br>";
echo "Image Height: ".$exif['COMPUTED']['Height']."<br>";
echo "Image Resolution: ".$exif['IFD0']['XResolution']."<br>";
echo "Image Orientation: ".$exif['IFD0']['Orientation']."<br>";
echo "Software Used: ".$exif['IFD0']['Software']."<br>";
echo "Date Edited: ".$exif['IFD0']['DateTime']."<br>";
echo "Original Created Date: ".$exif['EXIF']['DateTimeOriginal']."<br>";
}

Output

File Name: Photo130.jpg
File Size: 697559
File Date Time: September 22 2014 11:16:00.
File Mime Type: image/jpeg
Device Make: SAMSUNG
Device Model: SCH-S239
Image Width: 956
Image Height: 1144
Image Resolution: 720000/10000
Image Orientation: 1
Software Used: Adobe Photoshop CS3 Windows
Date Edited: 2014:09:22 16:45:58
Original Created Date: 2013:06:08 17:08:51

Call to undefined function exif_read_data()

What if you get Call to undefined function exif_read_data() error. This is because exif_read_data() function is not enabled in php.ini. If you have assess to php.ini file then uncomment extension=php_exif.dll in php.ini file. In php.ini you need to change the sequence as follows.
/*PHP INI SET UP for windows */
extension=php_mbstring.dll
extension=php_exif.dll
Top