Reading image EXIF dataPosted by Matt Thommes on June 5, 2009 | Post type: Gain Every image taken with a digital camera contains information stored as part of the image file itself, such as camera make/model, orientation, date/time the photo was taken, etc. You can view and extract this information with the right tools. One unique application might be to extract the latitude and longitude of the image file, and place it on a map which displays the location of each photo you shoot. Photo-sharing tools like Flickr will automatically extract the EXIF GPS data and apply that to the photo's extended description:
This example Flickr photo was taken with an Apple iPhone, with "Location Services" (under Settings) turned on, so GPS data is embedded as part of the image file. Other ways to view image EXIF dataBesides Flickr, you can view image EXIF data by manually opening each image in a program that can read the EXIF data for you. For example, Adobe Photoshop and Graphic Converter both let you view the EXIF data:
You can also obtain the EXIF data programmatically. Here is a good example of how to use PHP to obtain the EXIF data for an image file:
function get_exif_data($file) {
$exif = exif_read_data($file, 0, true);
return $exif;
}
$image_file = '/path/to/image.jpg';
$image_exif = get_exif_data($image_file);
echo "<pre>";
print_r($image_exif);
echo "</pre>";
The example code above (for an image taken with an Apple iPhone) would produce something like this:
Array
(
[FILE] => Array
(
[FileName] => image.jpg
[FileDateTime] => 1244222861
[FileSize] => 388321
[FileType] => 2
[MimeType] => image/jpeg
[SectionsFound] => ANY_TAG, IFD0, THUMBNAIL, EXIF, GPS
)
[COMPUTED] => Array
(
[html] => width="1600" height="1200"
[Height] => 1200
[Width] => 1600
[IsColor] => 1
[ByteOrderMotorola] => 1
[ApertureFNumber] => f/2.8
[Thumbnail.FileType] => 2
[Thumbnail.MimeType] => image/jpeg
)
[IFD0] => Array
(
[Make] => Apple
[Model] => iPhone
[Orientation] => 1
[XResolution] => 72/1
[YResolution] => 72/1
[ResolutionUnit] => 2
[DateTime] => 2009:06:03 11:31:25
[Exif_IFD_Pointer] => 171
[GPS_IFD_Pointer] => 317
)
[THUMBNAIL] => Array
(
[Compression] => 6
[Orientation] => 1
[XResolution] => 72/1
[YResolution] => 72/1
[ResolutionUnit] => 2
[JPEGInterchangeFormat] => 561
[JPEGInterchangeFormatLength] => 6495
)
[EXIF] => Array
(
[FNumber] => 14/5
[DateTimeOriginal] => 2009:06:03 11:31:25
[DateTimeDigitized] => 2009:06:03 11:31:25
[ColorSpace] => 1
[ExifImageWidth] => 1600
[ExifImageLength] => 1200
[UndefinedTag:0xA500] => 11/5
)
[GPS] => Array
(
[GPSLatitudeRef] => N
[GPSLatitude] => Array
(
[0] => 19/1
[1] => 2977/100
[2] => 0/1
)
[GPSLongitudeRef] => W
[GPSLongitude] => Array
(
[0] => 155/1
[1] => 5713/100
[2] => 0/1
)
[GPSTimeStamp] => Array
(
[0] => 11/1
[1] => 31/1
[2] => 2279/100
)
)
)
Please note: depending on the digital camera model, the above array items may differ slightly. With this array of data, you can do just about anything with your image from here. About the author(s)Matt Thommes is an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from a suburb of Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us. Comments
|
Quick Link to this postTTIP.me/2189 |
For Ruby programmers out there, check out the exifr gem.
Quick Link to this comment: http://TTIP.me/c5196