<?php defined("SYSPATH") or die("No direct script access.");
/*
Exifer 1.6
Extracts EXIF information from digital photos.
Originally created by:
Copyright © 2005 Jake Olefsky
http:// www.offsky.com/software/exif/index.php
jake@olefsky.com
This program is free software; you can redistribute it and/or modify it under the terms of
the GNU General Public License as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details. http:// www.gnu.org/copyleft/gpl.html
SUMMARY:
This script will correctly parse all of the EXIF data included in images taken
with digital cameras. It will read the IDF0, IDF1, SubIDF and InteroperabilityIFD
fields as well as parsing some of the MakerNote fields that vary depending on
camera make and model. This script parses more tags than the internal PHP exif
implementation and it will correctly identify and decode what all the values mean.
This version will correctly parse the MakerNote field for Nikon, Olympus, and Canon
digital cameras. Others will follow.
TESTED WITH:
Nikon CoolPix 700
Nikon CoolPix E3200
Nikon CoolPix 4500
Nikon CoolPix 950
Nikon Coolpix 5700
Canon PowerShot S200
Canon PowerShot S110
Olympus C2040Z
Olympus C960
Olumpus E-300
Olympus E-410
Olympus E-500
Olympus E-510
Olympus E-3
Canon Ixus
Canon EOS 300D
Canon Digital Rebel
Canon EOS 10D
Canon PowerShot G2
FujiFilm DX 10
FujiFilm MX-1200
FujiFilm FinePix2400
FujiFilm FinePix2600
FujiFilm FinePix S602
FujiFilm FinePix40i
Sony D700
Sony Cybershot
Kodak DC210
Kodak DC240
Kodak DC4800
Kodak DX3215
Ricoh RDC-5300
Sanyo VPC-G250
Sanyo VPC-SX550
Epson 3100z
VERSION HISTORY:
1.0 September 23, 2002
+ First Public Release
1.1 January 25, 2003
+ Gracefully handled the error case where you pass an empty string to this library
+ Fixed an inconsistency in the Olympus Camera parsing module
+ Added support for parsing the MakerNote of Canon images.
+ Modified how the imagefile is opened so it works for windows machines.
+ Correctly parses the FocalPlaneResolutionUnit and PhotometricInterpretation fields
+ Negative rational numbers are properly displayed
+ Strange old cameras that use Motorola endineness are now properly supported
+ Tested with several more cameras
Potential Problem: Negative Shorts and Negative Longs may not be correctly displayed, but I
have not yet found an example of negative shorts or longs being used.
1.2 March 30, 2003
+ Fixed an error that was displayed if you edited your image with WinXP's image viewer
+ Fixed a bug that caused some images saved from 3rd party software to not parse correctly
+ Changed the ExposureTime tag to display in fractional seconds rather than decimal
+ Updated the ShutterSpeedValue tag to have the units of 'sec'
+ Added support for parsing the MakeNote of FujiFilm images
+ Added support for parsing the MakeNote of Sanyo images
+ Fixed a bug with parsing some Olympus MakerNote tags
+ Tested with several more cameras
1.3 June 15, 2003
+ Fixed Canon MakerNote support for some models
(Canon has very difficult and inconsistent MakerNote syntax)
+ Negative signed shorts and negative signed longs are properly displayed
+ Several more tags are defined
+ More information in my comments about what each tag is
+ Parses and Displays GPS information if available
+ Tested with several more cameras
1.4 September 14, 2003
+ This software is now licensed under the GNU General Public License
+ Exposure time is now correctly displayed when the numerator is 10
+ Fixed the calculation and display of ShutterSpeedValue, ApertureValue and MaxApertureValue
+ Fixed a bug with the GPS code
+ Tested with several more cameras
1.5 February 18, 2005
+ It now gracefully deals with a passed in file that cannot be found.
+ Fixed a GPS bug for the parsing of Altitude and other signed rational numbers
+ Defined more values for Canon cameras.
+ Added 'bulb' detection for ShutterSpeed
+ Made script loading a little faster and less memory intensive.
+ Bug fixes
+ Better error reporting
+ Graceful failure for files with corrupt exif info.
+ QuickTime (including iPhoto) messes up the Makernote tag for certain photos (no workaround yet)
+ Now reads exif information when the jpeg markers are out of order
+ Gives raw data output for IPTC, COM and APP2 fields which are sometimes set by other applications
+ Improvements to Nikon Makernote parsing
1.6 March 25th, 2007 [Zenphoto]
+ Adopted into the Zenphoto gallery project, at http://www.zenphoto.org
+ Fixed a bug where strings had trailing null bytes.
+ Formatted selected strings better.
+ Added calculation of 35mm-equivalent focal length when possible.
+ Cleaned up code for readability and efficiency.
1.7 April 11th, 2008 [Zenphoto]
+ Fixed bug with newer Olympus cameras where number of fields was miscalculated leading to bad performance.
+ More logical fraction calculation for shutter speed.
*/
//================================================================================================
// Converts from Intel to Motorola endien. Just reverses the bytes (assumes hex is passed in)
//================================================================================================
function intel2Moto($intel) {
static $cache = array();
if (isset($cache[$intel])) {
return $cache[$intel];
}
$cache[$intel] = '';
$len = strlen($intel);
if ($len > 1000) {
debugLogBacktrace('intel2Moto called with unreasonable data string: length='.$len);
trigger_error(sprintf((string) t('intel2Moto called with unreasonable data string: length=%s. See debug log for details. (Setting DEBUG_EXIF to true might help locate problem images.)'),$len));
} else {
for($i = 0; $i <= $len; $i += 2) {
$cache[$intel] .= substr($intel, $len-$i, 2);
}
}
return $cache[$intel];
}
//================================================================================================
// Looks up the name of the tag
//================================================================================================
function lookup_tag($tag) {
switch($tag) {
// used by IFD0 'Camera Tags'
case '000b': $tag = 'ACDComment'; break; // text string up to 999 bytes long
case '00fe': $tag = 'ImageType'; break; // integer -2147483648 to 2147483647
case '0106': $tag = 'PhotometricInterpret'; break; // ?? Please send sample image with this tag
case '010e': $tag = 'ImageDescription'; break; // text string up to 999 bytes long
case '010f': $tag = 'Make'; break; // text string up to 999 bytes long
case '0110': $tag = 'Model'; break; // text string up to 999 bytes long
case '0112': $tag = 'Orientation'; break; // integer values 1-9
case '0115': $tag = 'SamplePerPixel'; break; // integer 0-65535
case '011a': $tag = 'xResolution'; break; // positive rational number
case '011b': $tag = 'yResolution'; break; // positive rational number
case '011c': $tag = 'PlanarConfig'; break; // integer values 1-2
case '0128': $tag = 'ResolutionUnit'; break; // integer values 1-3
case '0131': $tag = 'Software'; break; // text string up to 999 bytes long
case '0132': $tag = 'DateTime'; break; // YYYY:MM:DD HH:MM:SS
case '013b': $tag = 'Artist'; break; // text st