4 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
5 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
6 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
23 * @see http://exif.org/Exif2-2.PDF The Exif 2.2 specification
27 * @todo document (e.g. one-sentence class-overview description)
37 * Exif tag type definition
39 const BYTE = 1; # An 8-bit (1-byte) unsigned integer.
40 const ASCII = 2; # An 8-bit byte containing one 7-bit ASCII code. The final byte is terminated with NULL.
41 const SHORT = 3; # A 16-bit (2-byte) unsigned integer.
42 const LONG = 4; # A 32-bit (4-byte) unsigned integer.
43 const RATIONAL = 5; # Two LONGs. The first LONG is the numerator and the second LONG expresses the denominator
44 const UNDEFINED = 7; # An 8-bit byte that can take any value depending on the field definition
45 const SLONG = 9; # A 32-bit (4-byte) signed integer (2's complement notation),
46 const SRATIONAL = 10; # Two SLONGs. The first SLONG is the numerator and the second SLONG is the denominator.
49 * Exif tags grouped by category, the tagname itself is the key and the type
50 * is the value, in the case of more than one possible value type they are
51 * separated by commas.
56 * A one dimentional array of all Exif tags
61 * The raw Exif data returned by exif_read_data()
66 * A Filtered version of $mRawExifData that has been pruned of invalid
67 * tags and tags that contain content they shouldn't contain according
68 * to the Exif specification
70 var $mFilteredExifData;
73 * Filtered and formatted Exif data, see FormatExif::getFormattedData()
75 var $mFormattedExifData;
85 * The file being processed
90 * The basename of the file being processed
95 * The private log to log to, e.g. 'exif'
104 * @param $file String: filename.
106 function __construct( $file ) {
108 * Page numbers here refer to pages in the EXIF 2.2 standard
110 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
112 $this->mExifTags = array(
113 # TIFF Rev. 6.0 Attribute Information (p22)
115 # Tags relating to image structure
116 'structure' => array(
117 'ImageWidth' => Exif::SHORT.','.Exif::LONG, # Image width
118 'ImageLength' => Exif::SHORT.','.Exif::LONG, # Image height
119 'BitsPerSample' => Exif::SHORT, # Number of bits per component
120 # "When a primary image is JPEG compressed, this designation is not"
121 # "necessary and is omitted." (p23)
122 'Compression' => Exif::SHORT, # Compression scheme #p23
123 'PhotometricInterpretation' => Exif::SHORT, # Pixel composition #p23
124 'Orientation' => Exif::SHORT, # Orientation of image #p24
125 'SamplesPerPixel' => Exif::SHORT, # Number of components
126 'PlanarConfiguration' => Exif::SHORT, # Image data arrangement #p24
127 'YCbCrSubSampling' => Exif::SHORT, # Subsampling ratio of Y to C #p24
128 'YCbCrPositioning' => Exif::SHORT, # Y and C positioning #p24-25
129 'XResolution' => Exif::RATIONAL, # Image resolution in width direction
130 'YResolution' => Exif::RATIONAL, # Image resolution in height direction
131 'ResolutionUnit' => Exif::SHORT, # Unit of X and Y resolution #(p26)
134 # Tags relating to recording offset
136 'StripOffsets' => Exif::SHORT.','.Exif::LONG, # Image data location
137 'RowsPerStrip' => Exif::SHORT.','.Exif::LONG, # Number of rows per strip
138 'StripByteCounts' => Exif::SHORT.','.Exif::LONG, # Bytes per compressed strip
139 'JPEGInterchangeFormat' => Exif::SHORT.','.Exif::LONG, # Offset to JPEG SOI
140 'JPEGInterchangeFormatLength' => Exif::SHORT.','.Exif::LONG, # Bytes of JPEG data
143 # Tags relating to image data characteristics
144 'characteristics' => array(
145 'TransferFunction' => Exif::SHORT, # Transfer function
146 'WhitePoint' => Exif::RATIONAL, # White point chromaticity
147 'PrimaryChromaticities' => Exif::RATIONAL, # Chromaticities of primarities
148 'YCbCrCoefficients' => Exif::RATIONAL, # Color space transformation matrix coefficients #p27
149 'ReferenceBlackWhite' => Exif::RATIONAL # Pair of black and white reference values
154 'DateTime' => Exif::ASCII, # File change date and time
155 'ImageDescription' => Exif::ASCII, # Image title
156 'Make' => Exif::ASCII, # Image input equipment manufacturer
157 'Model' => Exif::ASCII, # Image input equipment model
158 'Software' => Exif::ASCII, # Software used
159 'Artist' => Exif::ASCII, # Person who created the image
160 'Copyright' => Exif::ASCII, # Copyright holder
164 # Exif IFD Attribute Information (p30-31)
166 # Tags relating to version
168 # TODO: NOTE: Nonexistence of this field is taken to mean nonconformance
169 # to the EXIF 2.1 AND 2.2 standards
170 'ExifVersion' => Exif::UNDEFINED, # Exif version
171 'FlashpixVersion' => Exif::UNDEFINED, # Supported Flashpix version #p32
174 # Tags relating to Image Data Characteristics
175 'characteristics' => array(
176 'ColorSpace' => Exif::SHORT, # Color space information #p32
179 # Tags relating to image configuration
180 'configuration' => array(
181 'ComponentsConfiguration' => Exif::UNDEFINED, # Meaning of each component #p33
182 'CompressedBitsPerPixel' => Exif::RATIONAL, # Image compression mode
183 'PixelYDimension' => Exif::SHORT.','.Exif::LONG, # Valid image width
184 'PixelXDimension' => Exif::SHORT.','.Exif::LONG, # Valind image height
187 # Tags relating to related user information
189 'MakerNote' => Exif::UNDEFINED, # Manufacturer notes
190 'UserComment' => Exif::UNDEFINED, # User comments #p34
193 # Tags relating to related file information
195 'RelatedSoundFile' => Exif::ASCII, # Related audio file
198 # Tags relating to date and time
199 'dateandtime' => array(
200 'DateTimeOriginal' => Exif::ASCII, # Date and time of original data generation #p36
201 'DateTimeDigitized' => Exif::ASCII, # Date and time of original data generation
202 'SubSecTime' => Exif::ASCII, # DateTime subseconds
203 'SubSecTimeOriginal' => Exif::ASCII, # DateTimeOriginal subseconds
204 'SubSecTimeDigitized' => Exif::ASCII, # DateTimeDigitized subseconds
207 # Tags relating to picture-taking conditions (p31)
208 'conditions' => array(
209 'ExposureTime' => Exif::RATIONAL, # Exposure time
210 'FNumber' => Exif::RATIONAL, # F Number
211 'ExposureProgram' => Exif::SHORT, # Exposure Program #p38
212 'SpectralSensitivity' => Exif::ASCII, # Spectral sensitivity
213 'ISOSpeedRatings' => Exif::SHORT, # ISO speed rating
214 'OECF' => Exif::UNDEFINED, # Optoelectronic conversion factor
215 'ShutterSpeedValue' => Exif::SRATIONAL, # Shutter speed
216 'ApertureValue' => Exif::RATIONAL, # Aperture
217 'BrightnessValue' => Exif::SRATIONAL, # Brightness
218 'ExposureBiasValue' => Exif::SRATIONAL, # Exposure bias
219 'MaxApertureValue' => Exif::RATIONAL, # Maximum land aperture
220 'SubjectDistance' => Exif::RATIONAL, # Subject distance
221 'MeteringMode' => Exif::SHORT, # Metering mode #p40
222 'LightSource' => Exif::SHORT, # Light source #p40-41
223 'Flash' => Exif::SHORT, # Flash #p41-42
224 'FocalLength' => Exif::RATIONAL, # Lens focal length
225 'SubjectArea' => Exif::SHORT, # Subject area
226 'FlashEnergy' => Exif::RATIONAL, # Flash energy
227 'SpatialFrequencyResponse' => Exif::UNDEFINED, # Spatial frequency response
228 'FocalPlaneXResolution' => Exif::RATIONAL, # Focal plane X resolution
229 'FocalPlaneYResolution' => Exif::RATIONAL, # Focal plane Y resolution
230 'FocalPlaneResolutionUnit' => Exif::SHORT, # Focal plane resolution unit #p46
231 'SubjectLocation' => Exif::SHORT, # Subject location
232 'ExposureIndex' => Exif::RATIONAL, # Exposure index
233 'SensingMethod' => Exif::SHORT, # Sensing method #p46
234 'FileSource' => Exif::UNDEFINED, # File source #p47
235 'SceneType' => Exif::UNDEFINED, # Scene type #p47
236 'CFAPattern' => Exif::UNDEFINED, # CFA pattern
237 'CustomRendered' => Exif::SHORT, # Custom image processing #p48
238 'ExposureMode' => Exif::SHORT, # Exposure mode #p48
239 'WhiteBalance' => Exif::SHORT, # White Balance #p49
240 'DigitalZoomRatio' => Exif::RATIONAL, # Digital zoom ration
241 'FocalLengthIn35mmFilm' => Exif::SHORT, # Focal length in 35 mm film
242 'SceneCaptureType' => Exif::SHORT, # Scene capture type #p49
243 'GainControl' => Exif::RATIONAL, # Scene control #p49-50
244 'Contrast' => Exif::SHORT, # Contrast #p50
245 'Saturation' => Exif::SHORT, # Saturation #p50
246 'Sharpness' => Exif::SHORT, # Sharpness #p50
247 'DeviceSettingDescription' => Exif::UNDEFINED, # Desice settings description
248 'SubjectDistanceRange' => Exif::SHORT, # Subject distance range #p51
252 'ImageUniqueID' => Exif::ASCII, # Unique image ID
256 # GPS Attribute Information (p52)
258 'GPSVersionID' => Exif::BYTE, # GPS tag version
259 'GPSLatitudeRef' => Exif::ASCII, # North or South Latitude #p52-53
260 'GPSLatitude' => Exif::RATIONAL, # Latitude
261 'GPSLongitudeRef' => Exif::ASCII, # East or West Longitude #p53
262 'GPSLongitude' => Exif::RATIONAL, # Longitude
263 'GPSAltitudeRef' => Exif::BYTE, # Altitude reference
264 'GPSAltitude' => Exif::RATIONAL, # Altitude
265 'GPSTimeStamp' => Exif::RATIONAL, # GPS time (atomic clock)
266 'GPSSatellites' => Exif::ASCII, # Satellites used for measurement
267 'GPSStatus' => Exif::ASCII, # Receiver status #p54
268 'GPSMeasureMode' => Exif::ASCII, # Measurement mode #p54-55
269 'GPSDOP' => Exif::RATIONAL, # Measurement precision
270 'GPSSpeedRef' => Exif::ASCII, # Speed unit #p55
271 'GPSSpeed' => Exif::RATIONAL, # Speed of GPS receiver
272 'GPSTrackRef' => Exif::ASCII, # Reference for direction of movement #p55
273 'GPSTrack' => Exif::RATIONAL, # Direction of movement
274 'GPSImgDirectionRef' => Exif::ASCII, # Reference for direction of image #p56
275 'GPSImgDirection' => Exif::RATIONAL, # Direction of image
276 'GPSMapDatum' => Exif::ASCII, # Geodetic survey data used
277 'GPSDestLatitudeRef' => Exif::ASCII, # Reference for latitude of destination #p56
278 'GPSDestLatitude' => Exif::RATIONAL, # Latitude destination
279 'GPSDestLongitudeRef' => Exif::ASCII, # Reference for longitude of destination #p57
280 'GPSDestLongitude' => Exif::RATIONAL, # Longitude of destination
281 'GPSDestBearingRef' => Exif::ASCII, # Reference for bearing of destination #p57
282 'GPSDestBearing' => Exif::RATIONAL, # Bearing of destination
283 'GPSDestDistanceRef' => Exif::ASCII, # Reference for distance to destination #p57-58
284 'GPSDestDistance' => Exif::RATIONAL, # Distance to destination
285 'GPSProcessingMethod' => Exif::UNDEFINED, # Name of GPS processing method
286 'GPSAreaInformation' => Exif::UNDEFINED, # Name of GPS area
287 'GPSDateStamp' => Exif::ASCII, # GPS date
288 'GPSDifferential' => Exif::SHORT, # GPS differential correction
293 $this->basename = wfBaseName( $this->file );
295 $this->makeFlatExifTags();
297 $this->debugFile( $this->basename, __FUNCTION__, true );
298 wfSuppressWarnings();
299 $data = exif_read_data( $this->file );
302 * exif_read_data() will return false on invalid input, such as
303 * when somebody uploads a file called something.jpeg
304 * containing random gibberish.
306 $this->mRawExifData = $data ? $data : array();
308 $this->makeFilteredData();
309 $this->makeFormattedData();
311 $this->debugFile( __FUNCTION__, false );
318 * Generate a flat list of the exif tags
320 function makeFlatExifTags() {
321 $this->extractTags( $this->mExifTags );
325 * A recursing extractor function used by makeFlatExifTags()
327 * Note: This used to use an array_walk function, but it made PHP5
328 * segfault, see `cvs diff -u -r 1.4 -r 1.5 Exif.php`
330 function extractTags( &$tagset ) {
331 foreach( $tagset as $key => $val ) {
332 if( is_array( $val ) ) {
333 $this->extractTags( $val );
335 $this->mFlatExifTags[$key] = $val;
341 * Make $this->mFilteredExifData
343 function makeFilteredData() {
344 $this->mFilteredExifData = $this->mRawExifData;
346 foreach( $this->mFilteredExifData as $k => $v ) {
347 if ( !in_array( $k, array_keys( $this->mFlatExifTags ) ) ) {
348 $this->debug( $v, __FUNCTION__, "'$k' is not a valid Exif tag" );
349 unset( $this->mFilteredExifData[$k] );
353 foreach( $this->mFilteredExifData as $k => $v ) {
354 if ( !$this->validate($k, $v) ) {
355 $this->debug( $v, __FUNCTION__, "'$k' contained invalid data" );
356 unset( $this->mFilteredExifData[$k] );
364 function makeFormattedData( ) {
365 $format = new FormatExif( $this->getFilteredData() );
366 $this->mFormattedExifData = $format->getFormattedData();
374 * Get $this->mRawExifData
377 return $this->mRawExifData;
381 * Get $this->mFilteredExifData
383 function getFilteredData() {
384 return $this->mFilteredExifData;
388 * Get $this->mFormattedExifData
390 function getFormattedData() {
391 return $this->mFormattedExifData;
396 * The version of the output format
398 * Before the actual metadata information is saved in the database we
399 * strip some of it since we don't want to save things like thumbnails
400 * which usually accompany Exif data. This value gets saved in the
401 * database along with the actual Exif data, and if the version in the
402 * database doesn't equal the value returned by this function the Exif
403 * data is regenerated.
407 public static function version() {
408 return 1; // We don't need no bloddy constants!
412 * Validates if a tag value is of the type it should be according to the Exif spec
416 * @param $in Mixed: the input value to check
419 function isByte( $in ) {
420 if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 255 ) {
421 $this->debug( $in, __FUNCTION__, true );
424 $this->debug( $in, __FUNCTION__, false );
429 function isASCII( $in ) {
430 if ( is_array( $in ) ) {
434 if ( preg_match( "/[^\x0a\x20-\x7e]/", $in ) ) {
435 $this->debug( $in, __FUNCTION__, 'found a character not in our whitelist' );
439 if ( preg_match( '/^\s*$/', $in ) ) {
440 $this->debug( $in, __FUNCTION__, 'input consisted solely of whitespace' );
447 function isShort( $in ) {
448 if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) {
449 $this->debug( $in, __FUNCTION__, true );
452 $this->debug( $in, __FUNCTION__, false );
457 function isLong( $in ) {
458 if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) {
459 $this->debug( $in, __FUNCTION__, true );
462 $this->debug( $in, __FUNCTION__, false );
467 function isRational( $in ) {
469 if ( !is_array( $in ) && @preg_match( '/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m ) ) { # Avoid division by zero
470 return $this->isLong( $m[1] ) && $this->isLong( $m[2] );
472 $this->debug( $in, __FUNCTION__, 'fed a non-fraction value' );
477 function isUndefined( $in ) {
478 if ( !is_array( $in ) && preg_match( '/^\d{4}$/', $in ) ) { // Allow ExifVersion and FlashpixVersion
479 $this->debug( $in, __FUNCTION__, true );
482 $this->debug( $in, __FUNCTION__, false );
487 function isSlong( $in ) {
488 if ( $this->isLong( abs( $in ) ) ) {
489 $this->debug( $in, __FUNCTION__, true );
492 $this->debug( $in, __FUNCTION__, false );
497 function isSrational( $in ) {
499 if ( !is_array( $in ) && preg_match( '/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m ) ) { # Avoid division by zero
500 return $this->isSlong( $m[0] ) && $this->isSlong( $m[1] );
502 $this->debug( $in, __FUNCTION__, 'fed a non-fraction value' );
509 * Validates if a tag has a legal value according to the Exif spec
513 * @param $tag String: the tag to check.
514 * @param $val Mixed: the value of the tag.
517 function validate( $tag, $val ) {
518 $debug = "tag is '$tag'";
519 // Does not work if not typecast
520 switch( (string)$this->mFlatExifTags[$tag] ) {
521 case (string)Exif::BYTE:
522 $this->debug( $val, __FUNCTION__, $debug );
523 return $this->isByte( $val );
524 case (string)Exif::ASCII:
525 $this->debug( $val, __FUNCTION__, $debug );
526 return $this->isASCII( $val );
527 case (string)Exif::SHORT:
528 $this->debug( $val, __FUNCTION__, $debug );
529 return $this->isShort( $val );
530 case (string)Exif::LONG:
531 $this->debug( $val, __FUNCTION__, $debug );
532 return $this->isLong( $val );
533 case (string)Exif::RATIONAL:
534 $this->debug( $val, __FUNCTION__, $debug );
535 return $this->isRational( $val );
536 case (string)Exif::UNDEFINED:
537 $this->debug( $val, __FUNCTION__, $debug );
538 return $this->isUndefined( $val );
539 case (string)Exif::SLONG:
540 $this->debug( $val, __FUNCTION__, $debug );
541 return $this->isSlong( $val );
542 case (string)Exif::SRATIONAL:
543 $this->debug( $val, __FUNCTION__, $debug );
544 return $this->isSrational( $val );
545 case (string)Exif::SHORT.','.Exif::LONG:
546 $this->debug( $val, __FUNCTION__, $debug );
547 return $this->isShort( $val ) || $this->isLong( $val );
549 $this->debug( $val, __FUNCTION__, "The tag '$tag' is unknown" );
555 * Convenience function for debugging output
560 * @param $fname String:
561 * @param $action Mixed: , default NULL.
563 function debug( $in, $fname, $action = NULL ) {
567 $type = gettype( $in );
568 $class = ucfirst( __CLASS__ );
569 if ( $type === 'array' )
570 $in = print_r( $in, true );
572 if ( $action === true )
573 wfDebugLog( $this->log, "$class::$fname: accepted: '$in' (type: $type)\n");
574 elseif ( $action === false )
575 wfDebugLog( $this->log, "$class::$fname: rejected: '$in' (type: $type)\n");
576 elseif ( $action === null )
577 wfDebugLog( $this->log, "$class::$fname: input was: '$in' (type: $type)\n");
579 wfDebugLog( $this->log, "$class::$fname: $action (type: $type; content: '$in')\n");
583 * Convenience function for debugging output
587 * @param $fname String: the name of the function calling this function
588 * @param $io Boolean: Specify whether we're beginning or ending
590 function debugFile( $fname, $io ) {
594 $class = ucfirst( __CLASS__ );
596 wfDebugLog( $this->log, "$class::$fname: begin processing: '{$this->basename}'\n" );
598 wfDebugLog( $this->log, "$class::$fname: end processing: '{$this->basename}'\n" );
605 * @todo document (e.g. one-sentence class-overview description)
610 * The Exif data to format
620 * @param $exif Array: the Exif data to format ( as returned by
621 * Exif::getFilteredData() )
623 function FormatExif( $exif ) {
624 $this->mExif = $exif;
628 * Numbers given by Exif user agents are often magical, that is they
629 * should be replaced by a detailed explanation depending on their
630 * value which most of the time are plain integers. This function
631 * formats Exif values into human readable form.
635 function getFormattedData() {
638 $tags =& $this->mExif;
640 $resolutionunit = !isset( $tags['ResolutionUnit'] ) || $tags['ResolutionUnit'] == 2 ? 2 : 3;
641 unset( $tags['ResolutionUnit'] );
643 foreach( $tags as $tag => $val ) {
648 $tags[$tag] = $this->msg( $tag, $val );
656 case 'PhotometricInterpretation':
659 $tags[$tag] = $this->msg( $tag, $val );
669 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
670 $tags[$tag] = $this->msg( $tag, $val );
678 case 'PlanarConfiguration':
681 $tags[$tag] = $this->msg( $tag, $val );
689 // TODO: YCbCrSubSampling
690 // TODO: YCbCrPositioning
694 switch( $resolutionunit ) {
696 $tags[$tag] = $this->msg( 'XYResolution', 'i', $this->formatNum( $val ) );
699 $this->msg( 'XYResolution', 'c', $this->formatNum( $val ) );
707 // TODO: YCbCrCoefficients #p27 (see annex E)
708 case 'ExifVersion': case 'FlashpixVersion':
709 $tags[$tag] = "$val"/100;
714 case 1: case 'FFFF.H':
715 $tags[$tag] = $this->msg( $tag, $val );
723 case 'ComponentsConfiguration':
725 case 0: case 1: case 2: case 3: case 4: case 5: case 6:
726 $tags[$tag] = $this->msg( $tag, $val );
735 case 'DateTimeOriginal':
736 case 'DateTimeDigitized':
737 if( $val == '0000:00:00 00:00:00' ) {
738 $tags[$tag] = wfMsg('exif-unknowndate');
739 } elseif( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d) (?:\d\d):(?:\d\d):(?:\d\d)$/', $val ) ) {
740 $tags[$tag] = $wgLang->timeanddate( wfTimestamp(TS_MW, $val) );
744 case 'ExposureProgram':
746 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
747 $tags[$tag] = $this->msg( $tag, $val );
755 case 'SubjectDistance':
756 $tags[$tag] = $this->msg( $tag, '', $this->formatNum( $val ) );
761 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 255:
762 $tags[$tag] = $this->msg( $tag, $val );
772 case 0: case 1: case 2: case 3: case 4: case 9: case 10: case 11:
773 case 12: case 13: case 14: case 15: case 17: case 18: case 19: case 20:
774 case 21: case 22: case 23: case 24: case 255:
775 $tags[$tag] = $this->msg( $tag, $val );
784 $flashDecode = array(
785 'fired' => $val & bindec( '00000001' ),
786 'return' => ($val & bindec( '00000110' )) >> 1,
787 'mode' => ($val & bindec( '00011000' )) >> 3,
788 'function' => ($val & bindec( '00100000' )) >> 5,
789 'redeye' => ($val & bindec( '01000000' )) >> 6,
790 // 'reserved' => ($val & bindec( '10000000' )) >> 7,
793 # We do not need to handle unknown values since all are used.
794 foreach( $flashDecode as $subTag => $subValue ) {
795 # We do not need any message for zeroed values.
796 if( $subTag != 'fired' && $subValue == 0) {
799 $fullTag = $tag . '-' . $subTag ;
800 $flashMsgs[] = $this->msg( $fullTag, $subValue );
802 $tags[$tag] = $wgLang->commaList( $flashMsgs );
805 case 'FocalPlaneResolutionUnit':
808 $tags[$tag] = $this->msg( $tag, $val );
816 case 'SensingMethod':
818 case 1: case 2: case 3: case 4: case 5: case 7: case 8:
819 $tags[$tag] = $this->msg( $tag, $val );
830 $tags[$tag] = $this->msg( $tag, $val );
841 $tags[$tag] = $this->msg( $tag, $val );
849 case 'CustomRendered':
852 $tags[$tag] = $this->msg( $tag, $val );
862 case 0: case 1: case 2:
863 $tags[$tag] = $this->msg( $tag, $val );
874 $tags[$tag] = $this->msg( $tag, $val );
882 case 'SceneCaptureType':
884 case 0: case 1: case 2: case 3:
885 $tags[$tag] = $this->msg( $tag, $val );
895 case 0: case 1: case 2: case 3: case 4:
896 $tags[$tag] = $this->msg( $tag, $val );
906 case 0: case 1: case 2:
907 $tags[$tag] = $this->msg( $tag, $val );
917 case 0: case 1: case 2:
918 $tags[$tag] = $this->msg( $tag, $val );
928 case 0: case 1: case 2:
929 $tags[$tag] = $this->msg( $tag, $val );
937 case 'SubjectDistanceRange':
939 case 0: case 1: case 2: case 3:
940 $tags[$tag] = $this->msg( $tag, $val );
948 case 'GPSLatitudeRef':
949 case 'GPSDestLatitudeRef':
952 $tags[$tag] = $this->msg( 'GPSLatitude', $val );
960 case 'GPSLongitudeRef':
961 case 'GPSDestLongitudeRef':
964 $tags[$tag] = $this->msg( 'GPSLongitude', $val );
975 $tags[$tag] = $this->msg( $tag, $val );
983 case 'GPSMeasureMode':
986 $tags[$tag] = $this->msg( $tag, $val );
995 case 'GPSDestDistanceRef':
997 case 'K': case 'M': case 'N':
998 $tags[$tag] = $this->msg( 'GPSSpeed', $val );
1007 case 'GPSImgDirectionRef':
1008 case 'GPSDestBearingRef':
1011 $tags[$tag] = $this->msg( 'GPSDirection', $val );
1019 case 'GPSDateStamp':
1020 $tags[$tag] = $wgLang->date( substr( $val, 0, 4 ) . substr( $val, 5, 2 ) . substr( $val, 8, 2 ) . '000000' );
1023 // This is not in the Exif standard, just a special
1024 // case for our purposes which enables wikis to wikify
1025 // the make, model and software name to link to their articles.
1029 $tags[$tag] = $this->msg( $tag, '', $val );
1032 case 'ExposureTime':
1033 // Show the pretty fraction as well as decimal version
1034 $tags[$tag] = wfMsg( 'exif-exposuretime-format',
1035 $this->formatFraction( $val ), $this->formatNum( $val ) );
1039 $tags[$tag] = wfMsg( 'exif-fnumber-format',
1040 $this->formatNum( $val ) );
1044 $tags[$tag] = wfMsg( 'exif-focallength-format',
1045 $this->formatNum( $val ) );
1049 $tags[$tag] = $this->formatNum( $val );
1058 * Convenience function for getFormattedData()
1062 * @param $tag String: the tag name to pass on
1063 * @param $val String: the value of the tag
1064 * @param $arg String: an argument to pass ($1)
1065 * @return string A wfMsg of "exif-$tag-$val" in lower case
1067 function msg( $tag, $val, $arg = null ) {
1072 return wfMsg( $wgContLang->lc( "exif-$tag-$val" ), $arg );
1076 * Format a number, convert numbers from fractions into floating point
1081 * @param $num Mixed: the value to format
1082 * @return mixed A floating point number or whatever we were fed
1084 function formatNum( $num ) {
1086 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) )
1087 return $m[2] != 0 ? $m[1] / $m[2] : $num;
1093 * Format a rational number, reducing fractions
1097 * @param $num Mixed: the value to format
1098 * @return mixed A floating point number or whatever we were fed
1100 function formatFraction( $num ) {
1102 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) ) {
1103 $numerator = intval( $m[1] );
1104 $denominator = intval( $m[2] );
1105 $gcd = $this->gcd( $numerator, $denominator );
1107 // 0 shouldn't happen! ;)
1108 return $numerator / $gcd . '/' . $denominator / $gcd;
1111 return $this->formatNum( $num );
1115 * Calculate the greatest common divisor of two integers.
1117 * @param $a Integer: FIXME
1118 * @param $b Integer: FIXME
1122 function gcd( $a, $b ) {
1124 // http://en.wikipedia.org/wiki/Euclidean_algorithm
1125 // Recursive form would be:
1129 return gcd( $b, $a % $b );
1132 $remainder = $a % $b;
1134 // tail recursion...
1143 * MW 1.6 compatibility
1145 define( 'MW_EXIF_BYTE', Exif::BYTE );
1146 define( 'MW_EXIF_ASCII', Exif::ASCII );
1147 define( 'MW_EXIF_SHORT', Exif::SHORT );
1148 define( 'MW_EXIF_LONG', Exif::LONG );
1149 define( 'MW_EXIF_RATIONAL', Exif::RATIONAL );
1150 define( 'MW_EXIF_UNDEFINED', Exif::UNDEFINED );
1151 define( 'MW_EXIF_SLONG', Exif::SLONG );
1152 define( 'MW_EXIF_SRATIONAL', Exif::SRATIONAL );