6 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
7 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
8 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
25 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
31 * @subpackage Metadata
40 * Exif tag type definition
42 const MW_EXIF_BYTE
= 1; # An 8-bit (1-byte) unsigned integer.
43 const MW_EXIF_ASCII
= 2; # An 8-bit byte containing one 7-bit ASCII code. The final byte is terminated with NULL.
44 const MW_EXIF_SHORT
= 3; # A 16-bit (2-byte) unsigned integer.
45 const MW_EXIF_LONG
= 4; # A 32-bit (4-byte) unsigned integer.
46 const MW_EXIF_RATIONAL
= 5; # Two LONGs. The first LONG is the numerator and the second LONG expresses the denominator
47 const MW_EXIF_UNDEFINED
= 7; # An 8-bit byte that can take any value depending on the field definition
48 const MW_EXIF_SLONG
= 9; # A 32-bit (4-byte) signed integer (2's complement notation),
49 const MW_EXIF_SRATIONAL
= 10; # Two SLONGs. The first SLONG is the numerator and the second SLONG is the denominator.
52 * Exif tags grouped by category, the tagname itself is the key and the type
53 * is the value, in the case of more than one possible value type they are
54 * seperated by commas.
59 * A one dimentional array of all Exif tags
64 * The raw Exif data returned by exif_read_data()
69 * A Filtered version of $mRawExifData that has been pruned of invalid
70 * tags and tags that contain content they shouldn't contain according
71 * to the Exif specification
73 var $mFilteredExifData;
76 * Filtered and formatted Exif data, see FormatExif::getFormattedData()
78 var $mFormattedExifData;
88 * The file being processed
93 * The basename of the file being processed
98 * The private log to log to
107 * @param $file String: filename.
109 function Exif( $file ) {
111 * Page numbers here refer to pages in the EXIF 2.2 standard
113 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
115 $this->mExifTags
= array(
116 # TIFF Rev. 6.0 Attribute Information (p22)
118 # Tags relating to image structure
119 'structure' => array(
120 'ImageWidth' => Exif
::MW_EXIF_SHORT
.','.Exif
::MW_EXIF_LONG
, # Image width
121 'ImageLength' => Exif
::MW_EXIF_SHORT
.','.Exif
::MW_EXIF_LONG
, # Image height
122 'BitsPerSample' => Exif
::MW_EXIF_SHORT
, # Number of bits per component
123 # "When a primary image is JPEG compressed, this designation is not"
124 # "necessary and is omitted." (p23)
125 'Compression' => Exif
::MW_EXIF_SHORT
, # Compression scheme #p23
126 'PhotometricInterpretation' => Exif
::MW_EXIF_SHORT
, # Pixel composition #p23
127 'Orientation' => Exif
::MW_EXIF_SHORT
, # Orientation of image #p24
128 'SamplesPerPixel' => Exif
::MW_EXIF_SHORT
, # Number of components
129 'PlanarConfiguration' => Exif
::MW_EXIF_SHORT
, # Image data arrangement #p24
130 'YCbCrSubSampling' => Exif
::MW_EXIF_SHORT
, # Subsampling ratio of Y to C #p24
131 'YCbCrPositioning' => Exif
::MW_EXIF_SHORT
, # Y and C positioning #p24-25
132 'XResolution' => Exif
::MW_EXIF_RATIONAL
, # Image resolution in width direction
133 'YResolution' => Exif
::MW_EXIF_RATIONAL
, # Image resolution in height direction
134 'ResolutionUnit' => Exif
::MW_EXIF_SHORT
, # Unit of X and Y resolution #(p26)
137 # Tags relating to recording offset
139 'StripOffsets' => Exif
::MW_EXIF_SHORT
.','.Exif
::MW_EXIF_LONG
, # Image data location
140 'RowsPerStrip' => Exif
::MW_EXIF_SHORT
.','.Exif
::MW_EXIF_LONG
, # Number of rows per strip
141 'StripByteCounts' => Exif
::MW_EXIF_SHORT
.','.Exif
::MW_EXIF_LONG
, # Bytes per compressed strip
142 'JPEGInterchangeFormat' => Exif
::MW_EXIF_SHORT
.','.Exif
::MW_EXIF_LONG
, # Offset to JPEG SOI
143 'JPEGInterchangeFormatLength' => Exif
::MW_EXIF_SHORT
.','.Exif
::MW_EXIF_LONG
, # Bytes of JPEG data
146 # Tags relating to image data characteristics
147 'characteristics' => array(
148 'TransferFunction' => Exif
::MW_EXIF_SHORT
, # Transfer function
149 'WhitePoint' => Exif
::MW_EXIF_RATIONAL
, # White point chromaticity
150 'PrimaryChromaticities' => Exif
::MW_EXIF_RATIONAL
, # Chromaticities of primarities
151 'YCbCrCoefficients' => Exif
::MW_EXIF_RATIONAL
, # Color space transformation matrix coefficients #p27
152 'ReferenceBlackWhite' => Exif
::MW_EXIF_RATIONAL
# Pair of black and white reference values
157 'DateTime' => Exif
::MW_EXIF_ASCII
, # File change date and time
158 'ImageDescription' => Exif
::MW_EXIF_ASCII
, # Image title
159 'Make' => Exif
::MW_EXIF_ASCII
, # Image input equipment manufacturer
160 'Model' => Exif
::MW_EXIF_ASCII
, # Image input equipment model
161 'Software' => Exif
::MW_EXIF_ASCII
, # Software used
162 'Artist' => Exif
::MW_EXIF_ASCII
, # Person who created the image
163 'Copyright' => Exif
::MW_EXIF_ASCII
, # Copyright holder
167 # Exif IFD Attribute Information (p30-31)
169 # Tags relating to version
171 # TODO: NOTE: Nonexistence of this field is taken to mean nonconformance
172 # to the EXIF 2.1 AND 2.2 standards
173 'ExifVersion' => Exif
::MW_EXIF_UNDEFINED
, # Exif version
174 'FlashpixVersion' => Exif
::MW_EXIF_UNDEFINED
, # Supported Flashpix version #p32
177 # Tags relating to Image Data Characteristics
178 'characteristics' => array(
179 'ColorSpace' => Exif
::MW_EXIF_SHORT
, # Color space information #p32
182 # Tags relating to image configuration
183 'configuration' => array(
184 'ComponentsConfiguration' => Exif
::MW_EXIF_UNDEFINED
, # Meaning of each component #p33
185 'CompressedBitsPerPixel' => Exif
::MW_EXIF_RATIONAL
, # Image compression mode
186 'PixelYDimension' => Exif
::MW_EXIF_SHORT
.','.Exif
::MW_EXIF_LONG
, # Valid image width
187 'PixelXDimension' => Exif
::MW_EXIF_SHORT
.','.Exif
::MW_EXIF_LONG
, # Valind image height
190 # Tags relating to related user information
192 'MakerNote' => Exif
::MW_EXIF_UNDEFINED
, # Manufacturer notes
193 'UserComment' => Exif
::MW_EXIF_UNDEFINED
, # User comments #p34
196 # Tags relating to related file information
198 'RelatedSoundFile' => Exif
::MW_EXIF_ASCII
, # Related audio file
201 # Tags relating to date and time
202 'dateandtime' => array(
203 'DateTimeOriginal' => Exif
::MW_EXIF_ASCII
, # Date and time of original data generation #p36
204 'DateTimeDigitized' => Exif
::MW_EXIF_ASCII
, # Date and time of original data generation
205 'SubSecTime' => Exif
::MW_EXIF_ASCII
, # DateTime subseconds
206 'SubSecTimeOriginal' => Exif
::MW_EXIF_ASCII
, # DateTimeOriginal subseconds
207 'SubSecTimeDigitized' => Exif
::MW_EXIF_ASCII
, # DateTimeDigitized subseconds
210 # Tags relating to picture-taking conditions (p31)
211 'conditions' => array(
212 'ExposureTime' => Exif
::MW_EXIF_RATIONAL
, # Exposure time
213 'FNumber' => Exif
::MW_EXIF_RATIONAL
, # F Number
214 'ExposureProgram' => Exif
::MW_EXIF_SHORT
, # Exposure Program #p38
215 'SpectralSensitivity' => Exif
::MW_EXIF_ASCII
, # Spectral sensitivity
216 'ISOSpeedRatings' => Exif
::MW_EXIF_SHORT
, # ISO speed rating
217 'OECF' => Exif
::MW_EXIF_UNDEFINED
, # Optoelectronic conversion factor
218 'ShutterSpeedValue' => Exif
::MW_EXIF_SRATIONAL
, # Shutter speed
219 'ApertureValue' => Exif
::MW_EXIF_RATIONAL
, # Aperture
220 'BrightnessValue' => Exif
::MW_EXIF_SRATIONAL
, # Brightness
221 'ExposureBiasValue' => Exif
::MW_EXIF_SRATIONAL
, # Exposure bias
222 'MaxApertureValue' => Exif
::MW_EXIF_RATIONAL
, # Maximum land aperture
223 'SubjectDistance' => Exif
::MW_EXIF_RATIONAL
, # Subject distance
224 'MeteringMode' => Exif
::MW_EXIF_SHORT
, # Metering mode #p40
225 'LightSource' => Exif
::MW_EXIF_SHORT
, # Light source #p40-41
226 'Flash' => Exif
::MW_EXIF_SHORT
, # Flash #p41-42
227 'FocalLength' => Exif
::MW_EXIF_RATIONAL
, # Lens focal length
228 'SubjectArea' => Exif
::MW_EXIF_SHORT
, # Subject area
229 'FlashEnergy' => Exif
::MW_EXIF_RATIONAL
, # Flash energy
230 'SpatialFrequencyResponse' => Exif
::MW_EXIF_UNDEFINED
, # Spatial frequency response
231 'FocalPlaneXResolution' => Exif
::MW_EXIF_RATIONAL
, # Focal plane X resolution
232 'FocalPlaneYResolution' => Exif
::MW_EXIF_RATIONAL
, # Focal plane Y resolution
233 'FocalPlaneResolutionUnit' => Exif
::MW_EXIF_SHORT
, # Focal plane resolution unit #p46
234 'SubjectLocation' => Exif
::MW_EXIF_SHORT
, # Subject location
235 'ExposureIndex' => Exif
::MW_EXIF_RATIONAL
, # Exposure index
236 'SensingMethod' => Exif
::MW_EXIF_SHORT
, # Sensing method #p46
237 'FileSource' => Exif
::MW_EXIF_UNDEFINED
, # File source #p47
238 'SceneType' => Exif
::MW_EXIF_UNDEFINED
, # Scene type #p47
239 'CFAPattern' => Exif
::MW_EXIF_UNDEFINED
, # CFA pattern
240 'CustomRendered' => Exif
::MW_EXIF_SHORT
, # Custom image processing #p48
241 'ExposureMode' => Exif
::MW_EXIF_SHORT
, # Exposure mode #p48
242 'WhiteBalance' => Exif
::MW_EXIF_SHORT
, # White Balance #p49
243 'DigitalZoomRatio' => Exif
::MW_EXIF_RATIONAL
, # Digital zoom ration
244 'FocalLengthIn35mmFilm' => Exif
::MW_EXIF_SHORT
, # Focal length in 35 mm film
245 'SceneCaptureType' => Exif
::MW_EXIF_SHORT
, # Scene capture type #p49
246 'GainControl' => Exif
::MW_EXIF_RATIONAL
, # Scene control #p49-50
247 'Contrast' => Exif
::MW_EXIF_SHORT
, # Contrast #p50
248 'Saturation' => Exif
::MW_EXIF_SHORT
, # Saturation #p50
249 'Sharpness' => Exif
::MW_EXIF_SHORT
, # Sharpness #p50
250 'DeviceSettingDescription' => Exif
::MW_EXIF_UNDEFINED
, # Desice settings description
251 'SubjectDistanceRange' => Exif
::MW_EXIF_SHORT
, # Subject distance range #p51
255 'ImageUniqueID' => Exif
::MW_EXIF_ASCII
, # Unique image ID
259 # GPS Attribute Information (p52)
261 'GPSVersionID' => Exif
::MW_EXIF_BYTE
, # GPS tag version
262 'GPSLatitudeRef' => Exif
::MW_EXIF_ASCII
, # North or South Latitude #p52-53
263 'GPSLatitude' => Exif
::MW_EXIF_RATIONAL
, # Latitude
264 'GPSLongitudeRef' => Exif
::MW_EXIF_ASCII
, # East or West Longitude #p53
265 'GPSLongitude' => Exif
::MW_EXIF_RATIONAL
, # Longitude
266 'GPSAltitudeRef' => Exif
::MW_EXIF_BYTE
, # Altitude reference
267 'GPSAltitude' => Exif
::MW_EXIF_RATIONAL
, # Altitude
268 'GPSTimeStamp' => Exif
::MW_EXIF_RATIONAL
, # GPS time (atomic clock)
269 'GPSSatellites' => Exif
::MW_EXIF_ASCII
, # Satellites used for measurement
270 'GPSStatus' => Exif
::MW_EXIF_ASCII
, # Receiver status #p54
271 'GPSMeasureMode' => Exif
::MW_EXIF_ASCII
, # Measurement mode #p54-55
272 'GPSDOP' => Exif
::MW_EXIF_RATIONAL
, # Measurement precision
273 'GPSSpeedRef' => Exif
::MW_EXIF_ASCII
, # Speed unit #p55
274 'GPSSpeed' => Exif
::MW_EXIF_RATIONAL
, # Speed of GPS receiver
275 'GPSTrackRef' => Exif
::MW_EXIF_ASCII
, # Reference for direction of movement #p55
276 'GPSTrack' => Exif
::MW_EXIF_RATIONAL
, # Direction of movement
277 'GPSImgDirectionRef' => Exif
::MW_EXIF_ASCII
, # Reference for direction of image #p56
278 'GPSImgDirection' => Exif
::MW_EXIF_RATIONAL
, # Direction of image
279 'GPSMapDatum' => Exif
::MW_EXIF_ASCII
, # Geodetic survey data used
280 'GPSDestLatitudeRef' => Exif
::MW_EXIF_ASCII
, # Reference for latitude of destination #p56
281 'GPSDestLatitude' => Exif
::MW_EXIF_RATIONAL
, # Latitude destination
282 'GPSDestLongitudeRef' => Exif
::MW_EXIF_ASCII
, # Reference for longitude of destination #p57
283 'GPSDestLongitude' => Exif
::MW_EXIF_RATIONAL
, # Longitude of destination
284 'GPSDestBearingRef' => Exif
::MW_EXIF_ASCII
, # Reference for bearing of destination #p57
285 'GPSDestBearing' => Exif
::MW_EXIF_RATIONAL
, # Bearing of destination
286 'GPSDestDistanceRef' => Exif
::MW_EXIF_ASCII
, # Reference for distance to destination #p57-58
287 'GPSDestDistance' => Exif
::MW_EXIF_RATIONAL
, # Distance to destination
288 'GPSProcessingMethod' => Exif
::MW_EXIF_UNDEFINED
, # Name of GPS processing method
289 'GPSAreaInformation' => Exif
::MW_EXIF_UNDEFINED
, # Name of GPS area
290 'GPSDateStamp' => Exif
::MW_EXIF_ASCII
, # GPS date
291 'GPSDifferential' => Exif
::MW_EXIF_SHORT
, # GPS differential correction
296 $this->basename
= basename( $this->file
);
298 $this->makeFlatExifTags();
300 $this->debugFile( $this->basename
, __FUNCTION__
, true );
301 wfSuppressWarnings();
302 $data = exif_read_data( $this->file
);
305 * exif_read_data() will return false on invalid input, such as
306 * when somebody uploads a file called something.jpeg
307 * containing random gibberish.
309 $this->mRawExifData
= $data ?
$data : array();
311 $this->makeFilteredData();
312 $this->makeFormattedData();
314 $this->debugFile( __FUNCTION__
, false );
321 * Generate a flat list of the exif tags
323 function makeFlatExifTags() {
324 $this->extractTags( $this->mExifTags
);
328 * A recursing extractor function used by makeFlatExifTags()
330 * Note: This used to use an array_walk function, but it made PHP5
331 * segfault, see `cvs diff -u -r 1.4 -r 1.5 Exif.php`
333 function extractTags( &$tagset ) {
334 foreach( $tagset as $key => $val ) {
335 if( is_array( $val ) ) {
336 $this->extractTags( $val );
338 $this->mFlatExifTags
[$key] = $val;
344 * Make $this->mFilteredExifData
346 function makeFilteredData() {
347 $this->mFilteredExifData
= $this->mRawExifData
;
349 foreach( $this->mFilteredExifData
as $k => $v ) {
350 if ( !in_array( $k, array_keys( $this->mFlatExifTags
) ) ) {
351 $this->debug( $v, __FUNCTION__
, "'$k' is not a valid Exif tag" );
352 unset( $this->mFilteredExifData
[$k] );
356 foreach( $this->mFilteredExifData
as $k => $v ) {
357 if ( !$this->validate($k, $v) ) {
358 $this->debug( $v, __FUNCTION__
, "'$k' contained invalid data" );
359 unset( $this->mFilteredExifData
[$k] );
367 function makeFormattedData( ) {
368 $format = new FormatExif( $this->getFilteredData() );
369 $this->mFormattedExifData
= $format->getFormattedData();
377 * Get $this->mRawExifData
380 return $this->mRawExifData
;
384 * Get $this->mFilteredExifData
386 function getFilteredData() {
387 return $this->mFilteredExifData
;
391 * Get $this->mFormattedExifData
393 function getFormattedData() {
394 return $this->mFormattedExifData
;
399 * The version of the output format
401 * Before the actual metadata information is saved in the database we
402 * strip some of it since we don't want to save things like thumbnails
403 * which usually accompany Exif data. This value gets saved in the
404 * database along with the actual Exif data, and if the version in the
405 * database doesn't equal the value returned by this function the Exif
406 * data is regenerated.
411 return 1; // We don't need no bloddy constants!
415 * Validates if a tag value is of the type it should be according to the Exif spec
419 * @param $in Mixed: the input value to check
422 function isByte( $in ) {
423 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 255 ) {
424 $this->debug( $in, __FUNCTION__
, true );
427 $this->debug( $in, __FUNCTION__
, false );
432 function isASCII( $in ) {
433 if ( preg_match( "/[^\x0a\x20-\x7e]/", $in ) ) {
434 $this->debug( $in, __FUNCTION__
, 'found a character not in our whitelist' );
438 if ( preg_match( "/^\s*$/", $in ) ) {
439 $this->debug( $in, __FUNCTION__
, 'input consisted solely of whitespace' );
446 function isShort( $in ) {
447 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) {
448 $this->debug( $in, __FUNCTION__
, true );
451 $this->debug( $in, __FUNCTION__
, false );
456 function isLong( $in ) {
457 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) {
458 $this->debug( $in, __FUNCTION__
, true );
461 $this->debug( $in, __FUNCTION__
, false );
466 function isRational( $in ) {
467 if ( @preg_match
( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
468 return $this->isLong( $m[1] ) && $this->isLong( $m[2] );
470 $this->debug( $in, __FUNCTION__
, 'fed a non-fraction value' );
475 function isUndefined( $in ) {
476 if ( preg_match( "/^\d{4}$/", $in ) ) { // Allow ExifVersion and FlashpixVersion
477 $this->debug( $in, __FUNCTION__
, true );
480 $this->debug( $in, __FUNCTION__
, false );
485 function isSlong( $in ) {
486 if ( $this->isLong( abs( $in ) ) ) {
487 $this->debug( $in, __FUNCTION__
, true );
490 $this->debug( $in, __FUNCTION__
, false );
495 function isSrational( $in ) {
496 if ( preg_match( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
497 return $this->isSlong( $m[0] ) && $this->isSlong( $m[1] );
499 $this->debug( $in, __FUNCTION__
, 'fed a non-fraction value' );
506 * Validates if a tag has a legal value according to the Exif spec
510 * @param $tag String: the tag to check.
511 * @param $val Mixed: the value of the tag.
514 function validate( $tag, $val ) {
515 $debug = "tag is '$tag'";
516 // Fucks up if not typecast
517 switch( (string)$this->mFlatExifTags
[$tag] ) {
518 case (string)Exif
::MW_EXIF_BYTE
:
519 $this->debug( $val, __FUNCTION__
, $debug );
520 return $this->isByte( $val );
521 case (string)Exif
::MW_EXIF_ASCII
:
522 $this->debug( $val, __FUNCTION__
, $debug );
523 return $this->isASCII( $val );
524 case (string)Exif
::MW_EXIF_SHORT
:
525 $this->debug( $val, __FUNCTION__
, $debug );
526 return $this->isShort( $val );
527 case (string)Exif
::MW_EXIF_LONG
:
528 $this->debug( $val, __FUNCTION__
, $debug );
529 return $this->isLong( $val );
530 case (string)Exif
::MW_EXIF_RATIONAL
:
531 $this->debug( $val, __FUNCTION__
, $debug );
532 return $this->isRational( $val );
533 case (string)Exif
::MW_EXIF_UNDEFINED
:
534 $this->debug( $val, __FUNCTION__
, $debug );
535 return $this->isUndefined( $val );
536 case (string)Exif
::MW_EXIF_SLONG
:
537 $this->debug( $val, __FUNCTION__
, $debug );
538 return $this->isSlong( $val );
539 case (string)Exif
::MW_EXIF_SRATIONAL
:
540 $this->debug( $val, __FUNCTION__
, $debug );
541 return $this->isSrational( $val );
542 case (string)Exif
::MW_EXIF_SHORT
.','.Exif
::MW_EXIF_LONG
:
543 $this->debug( $val, __FUNCTION__
, $debug );
544 return $this->isShort( $val ) ||
$this->isLong( $val );
546 $this->debug( $val, __FUNCTION__
, "The tag '$tag' is unknown" );
552 * Conviniance function for debugging output
557 * @param $fname String:
558 * @param $action Mixed: , default NULL.
560 function debug( $in, $fname, $action = NULL ) {
561 $type = gettype( $in );
562 $class = ucfirst( __CLASS__
);
563 if ( $type === 'array' )
564 $in = print_r( $in, true );
566 if ( $action === true )
567 wfDebugLog( $this->log
, "$class::$fname: accepted: '$in' (type: $type)\n");
568 elseif ( $action === false )
569 wfDebugLog( $this->log
, "$class::$fname: rejected: '$in' (type: $type)\n");
570 elseif ( $action === null )
571 wfDebugLog( $this->log
, "$class::$fname: input was: '$in' (type: $type)\n");
573 wfDebugLog( $this->log
, "$class::$fname: $action (type: $type; content: '$in')\n");
577 * Conviniance function for debugging output
581 * @param $fname String: the name of the function calling this function
582 * @param $io Boolean: Specify whether we're beginning or ending
584 function debugFile( $fname, $io ) {
585 $class = ucfirst( __CLASS__
);
587 wfDebugLog( $this->log
, "$class::$fname: begin processing: '{$this->basename}'\n" );
589 wfDebugLog( $this->log
, "$class::$fname: end processing: '{$this->basename}'\n" );
597 * @subpackage Metadata
601 * The Exif data to format
611 * @param $exif Array: the Exif data to format ( as returned by
612 * Exif::getFilteredData() )
614 function FormatExif( $exif ) {
615 $this->mExif
= $exif;
619 * Numbers given by Exif user agents are often magical, that is they
620 * should be replaced by a detailed explanation depending on their
621 * value which most of the time are plain integers. This function
622 * formats Exif values into human readable form.
626 function getFormattedData() {
629 $tags =& $this->mExif
;
631 $resolutionunit = !isset( $tags['ResolutionUnit'] ) ||
$tags['ResolutionUnit'] == 2 ?
2 : 3;
632 unset( $tags['ResolutionUnit'] );
634 foreach( $tags as $tag => $val ) {
639 $tags[$tag] = $this->msg( $tag, $val );
647 case 'PhotometricInterpretation':
650 $tags[$tag] = $this->msg( $tag, $val );
660 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
661 $tags[$tag] = $this->msg( $tag, $val );
669 case 'PlanarConfiguration':
672 $tags[$tag] = $this->msg( $tag, $val );
680 // TODO: YCbCrSubSampling
681 // TODO: YCbCrPositioning
685 switch( $resolutionunit ) {
687 $tags[$tag] = $this->msg( 'XYResolution', 'i', $this->formatNum( $val ) );
690 $this->msg( 'XYResolution', 'c', $this->formatNum( $val ) );
698 // TODO: YCbCrCoefficients #p27 (see annex E)
699 case 'ExifVersion': case 'FlashpixVersion':
700 $tags[$tag] = "$val"/100;
705 case 1: case 'FFFF.H':
706 $tags[$tag] = $this->msg( $tag, $val );
714 case 'ComponentsConfiguration':
716 case 0: case 1: case 2: case 3: case 4: case 5: case 6:
717 $tags[$tag] = $this->msg( $tag, $val );
726 case 'DateTimeOriginal':
727 case 'DateTimeDigitized':
728 if( preg_match( "/^(\d{4}):(\d\d):(\d\d) (\d\d):(\d\d):(\d\d)$/", $val ) ) {
729 $tags[$tag] = $wgLang->timeanddate( wfTimestamp(TS_MW
, $val) );
733 case 'ExposureProgram':
735 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
736 $tags[$tag] = $this->msg( $tag, $val );
744 case 'SubjectDistance':
745 $tags[$tag] = $this->msg( $tag, '', $this->formatNum( $val ) );
750 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 255:
751 $tags[$tag] = $this->msg( $tag, $val );
761 case 0: case 1: case 2: case 3: case 4: case 9: case 10: case 11:
762 case 12: case 13: case 14: case 15: case 17: case 18: case 19: case 20:
763 case 21: case 22: case 23: case 24: case 255:
764 $tags[$tag] = $this->msg( $tag, $val );
773 case 'FocalPlaneResolutionUnit':
776 $tags[$tag] = $this->msg( $tag, $val );
784 case 'SensingMethod':
786 case 1: case 2: case 3: case 4: case 5: case 7: case 8:
787 $tags[$tag] = $this->msg( $tag, $val );
798 $tags[$tag] = $this->msg( $tag, $val );
809 $tags[$tag] = $this->msg( $tag, $val );
817 case 'CustomRendered':
820 $tags[$tag] = $this->msg( $tag, $val );
830 case 0: case 1: case 2:
831 $tags[$tag] = $this->msg( $tag, $val );
842 $tags[$tag] = $this->msg( $tag, $val );
850 case 'SceneCaptureType':
852 case 0: case 1: case 2: case 3:
853 $tags[$tag] = $this->msg( $tag, $val );
863 case 0: case 1: case 2: case 3: case 4:
864 $tags[$tag] = $this->msg( $tag, $val );
874 case 0: case 1: case 2:
875 $tags[$tag] = $this->msg( $tag, $val );
885 case 0: case 1: case 2:
886 $tags[$tag] = $this->msg( $tag, $val );
896 case 0: case 1: case 2:
897 $tags[$tag] = $this->msg( $tag, $val );
905 case 'SubjectDistanceRange':
907 case 0: case 1: case 2: case 3:
908 $tags[$tag] = $this->msg( $tag, $val );
916 case 'GPSLatitudeRef':
917 case 'GPSDestLatitudeRef':
920 $tags[$tag] = $this->msg( 'GPSLatitude', $val );
928 case 'GPSLongitudeRef':
929 case 'GPSDestLongitudeRef':
932 $tags[$tag] = $this->msg( 'GPSLongitude', $val );
943 $tags[$tag] = $this->msg( $tag, $val );
951 case 'GPSMeasureMode':
954 $tags[$tag] = $this->msg( $tag, $val );
963 case 'GPSDestDistanceRef':
965 case 'K': case 'M': case 'N':
966 $tags[$tag] = $this->msg( 'GPSSpeed', $val );
975 case 'GPSImgDirectionRef':
976 case 'GPSDestBearingRef':
979 $tags[$tag] = $this->msg( 'GPSDirection', $val );
988 $tags[$tag] = $wgLang->date( substr( $val, 0, 4 ) . substr( $val, 5, 2 ) . substr( $val, 8, 2 ) . '000000' );
991 // This is not in the Exif standard, just a special
992 // case for our purposes which enables wikis to wikify
993 // the make, model and software name to link to their articles.
997 $tags[$tag] = $this->msg( $tag, '', $val );
1000 case 'ExposureTime':
1001 // Show the pretty fraction as well as decimal version
1002 $tags[$tag] = wfMsg( 'exif-exposuretime-format',
1003 $this->formatFraction( $val ), $this->formatNum( $val ) );
1007 $tags[$tag] = wfMsg( 'exif-fnumber-format',
1008 $this->formatNum( $val ) );
1012 $tags[$tag] = wfMsg( 'exif-focallength-format',
1013 $this->formatNum( $val ) );
1017 $tags[$tag] = $this->formatNum( $val );
1026 * Conviniance function for getFormattedData()
1030 * @param $tag String: the tag name to pass on
1031 * @param $val String: the value of the tag
1032 * @param $arg String: an argument to pass ($1)
1033 * @return string A wfMsg of "exif-$tag-$val" in lower case
1035 function msg( $tag, $val, $arg = null ) {
1040 return wfMsg( $wgContLang->lc( "exif-$tag-$val" ), $arg );
1044 * Format a number, convert numbers from fractions into floating point
1049 * @param $num Mixed: the value to format
1050 * @return mixed A floating point number or whatever we were fed
1052 function formatNum( $num ) {
1053 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) )
1054 return $m[2] != 0 ?
$m[1] / $m[2] : $num;
1060 * Format a rational number, reducing fractions
1064 * @param $num Mixed: the value to format
1065 * @return mixed A floating point number or whatever we were fed
1067 function formatFraction( $num ) {
1068 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) ) {
1069 $numerator = intval( $m[1] );
1070 $denominator = intval( $m[2] );
1071 $gcd = $this->gcd( $numerator, $denominator );
1073 // 0 shouldn't happen! ;)
1074 return $numerator / $gcd . '/' . $denominator / $gcd;
1077 return $this->formatNum( $num );
1081 * Calculate the greatest common divisor of two integers.
1083 * @param $a Integer: FIXME
1084 * @param $b Integer: FIXME
1088 function gcd( $a, $b ) {
1090 // http://en.wikipedia.org/wiki/Euclidean_algorithm
1091 // Recursive form would be:
1095 return gcd( $b, $a % $b );
1098 $remainder = $a %
$b;
1100 // tail recursion...