Extract EXIF data from your pictures!

29
Dec
0

Almost every digital camera these days inserts EXIF data information into their JPEG (.jpg) files. EXIF stands for Exchangeable Image File Format and is a standard for storing interchange information in image files. The format is part of the DCF standard created by JEITA for interoperability reasons between imaging devices.

So why use it? For the purposes of the photo galleries on this site, the EXIF data will allow you to see a handful of camera settings used to generate the photo, the date/time the photo was taken, and any copyrights on them (they are all ©1997- by myself, so, no suprise there really, though there may be some exceptions that I’m not aware of :-p ).

To view the EXIF data, hover your mouse over the thumbnail and a Tooltip box should appear with the information. This page is a good example of it in action. EXIF data should be available for all my photos using my gallery function taken after July 2004. Exceptions to this are of the panoramic shots, as that was manually stitched together from multiple photos.

You can use this code as long as it follows the following Creative Commons License terms.

Code:

//*************************************************************
//Function: getExifTags()
//Author : (c) Thomas Ng, Dec 28th, 2005.
//Purpose : Returns all of the EXIF tags from the photo pointed
// to by $filePath. EXIF fields contains information
// about the digital photo such as shutter speed,
// date/time taken, focal length, and exposure time.
// Available EXIF fields may vary from camera to
// camera. A list of fields available on the Nikon D70
// are as follows:
/*
ColorSpace CompressedBitsPerPixel Contrast
CustomRendered DateTimeDigitized DateTimeOriginal
DigitalZoomRatio ExifVersion ExposureBiasValue
ExposureMode ExposureProgram ExposureTime
FileSource FiredFlashpixVersion FNumber
FocalLength FocalLengthIn35mmFilm FunctionGainControl
LightSource MaxApertureValue MeteringMode
Mode PixelXDimension PixelYDimension
RedEyeMode Return Saturation
SceneCaptureType SceneType SensingMethod
Sharpness SubjectDistanceRange WhiteBalance
*/
//Usage :
// $testTags = getExifTags(”/full/path/to/file.jpg”);
// print “FNumber: ” . $testTags['FNumber'] . “<br />”;
// print “FocalLength: ” . $testTags['FocalLength'];

//*************************************************************
function getExifTags($file)
{
$fdataBinary = file_get_contents($file);
#Find all lines with: ^\s*<exif:.*>.*</exif:.*>
$pattern =
‘/^\s*\<exif\:[a-zA-Z35]+\>.*\<\/exif\:[a-zA-Z35]+\>/m’;
$sts = preg_match_all($pattern,$fdataBinary,$exifTags);

if ($sts != FALSE)
{
foreach ( $exifTags[0] as $element )
{
##KEY: find <exif:.*> tagName, remove <exif: and >
$pattern = ‘/(^\s*)?\<exif\:[a-zA-Z35]+\>/m’;
#$key_this contains ^\s*<exif:.*>
$sts = preg_match($pattern, $element, $key_this);
if ($sts == FALSE)
print “cannot preg_match for key”;
#strip line of the ^\s*<exif: beginning and > chars
$pattern = ‘/(^\s*\<exif\:)?(\>)?/m’;
$key = preg_replace($pattern, ”, $key_this);

##VALUE: find <exif:.*>.*</exif:.*>, strip off tags
$pattern =
‘/^\s*\<exif\:[a-zA-Z35]+\>.*\<\/exif\:[a-zA-Z35]+\>/m’;
#$value_this now contains ^\s<exif.*>.*</exif:.*>
$sts = preg_match($pattern, $element, $value_this);
if ($sts == FALSE)
print “cannot preg_match for value”;
#strip <exif:.*> and </exif:.*> tags
$pattern = ‘/(^\s*)?\<(\/)?exif\:[a-zA-Z35]+\>/m’;
#$value contains the value only from the same key
$value = preg_replace($pattern, ”, $value_this);

##add to a new key<–>value associative array
$EXIFDATA[$key[0]] = $value[0];
}
}
#Return entire key<–>value array, even if NULL
return $EXIFDATA;
}

No Comments

No Comments

No comments yet.

Leave a comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

RSS feed for comments on this post