2 if ( !defined( 'MEDIAWIKI' ) ) die();
7 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
8 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
9 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 * http://www.gnu.org/copyleft/gpl.html
26 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
31 * Exif tag type definition
33 define('MW_EXIF_BYTE', 1); # An 8-bit (1-byte) unsigned integer.
34 define('MW_EXIF_ASCII', 2); # An 8-bit byte containing one 7-bit ASCII code. The final byte is terminated with NULL.
35 define('MW_EXIF_SHORT', 3); # A 16-bit (2-byte) unsigned integer.
36 define('MW_EXIF_LONG', 4); # A 32-bit (4-byte) unsigned integer.
37 define('MW_EXIF_RATIONAL', 5); # Two LONGs. The first LONG is the numerator and the second LONG expresses the denominator
38 define('MW_EXIF_UNDEFINED', 7); # An 8-bit byte that can take any value depending on the field definition
39 define('MW_EXIF_SLONG', 9); # A 32-bit (4-byte) signed integer (2's complement notation),
40 define('MW_EXIF_SRATIONAL', 10); # Two SLONGs. The first SLONG is the numerator and the second SLONG is the denominator.
46 * @subpackage Metadata
55 * Exif tags grouped by category, the tagname itself is the key and the type
56 * is the value, in the case of more than one possible value type they are
57 * seperated by commas.
62 * A one dimentional array of all Exif tags
67 * The raw Exif data returned by exif_read_data()
72 * A Filtered version of $mRawExifData that has been pruned of invalid
73 * tags and tags that contain content they shouldn't contain according
74 * to the Exif specification
76 var $mFilteredExifData;
79 * Filtered and formatted Exif data, see FormatExif::getFormattedData()
81 var $mFormattedExifData;
86 * The private log to log to
98 function Exif( $file ) {
100 * Page numbers here refer to pages in the EXIF 2.2 standard
102 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
104 $this->mExifTags
= array(
105 # TIFF Rev. 6.0 Attribute Information (p22)
107 # Tags relating to image structure
108 'structure' => array(
109 'ImageWidth' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Image width
110 'ImageLength' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Image height
111 'BitsPerSample' => MW_EXIF_SHORT
, # Number of bits per component
112 # "When a primary image is JPEG compressed, this designation is not"
113 # "necessary and is omitted." (p23)
114 'Compression' => MW_EXIF_SHORT
, # Compression scheme #p23
115 'PhotometricInterpretation' => MW_EXIF_SHORT
, # Pixel composition #p23
116 'Orientation' => MW_EXIF_SHORT
, # Orientation of image #p24
117 'SamplesPerPixel' => MW_EXIF_SHORT
, # Number of components
118 'PlanarConfiguration' => MW_EXIF_SHORT
, # Image data arrangement #p24
119 'YCbCrSubSampling' => MW_EXIF_SHORT
, # Subsampling ratio of Y to C #p24
120 'YCbCrPositioning' => MW_EXIF_SHORT
, # Y and C positioning #p24-25
121 'XResolution' => MW_EXIF_RATIONAL
, # Image resolution in width direction
122 'YResolution' => MW_EXIF_RATIONAL
, # Image resolution in height direction
123 'ResolutionUnit' => MW_EXIF_SHORT
, # Unit of X and Y resolution #(p26)
126 # Tags relating to recording offset
128 'StripOffsets' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Image data location
129 'RowsPerStrip' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Number of rows per strip
130 'StripByteCounts' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Bytes per compressed strip
131 'JPEGInterchangeFormat' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Offset to JPEG SOI
132 'JPEGInterchangeFormatLength' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Bytes of JPEG data
135 # Tags relating to image data characteristics
136 'characteristics' => array(
137 'TransferFunction' => MW_EXIF_SHORT
, # Transfer function
138 'WhitePoint' => MW_EXIF_RATIONAL
, # White point chromaticity
139 'PrimaryChromaticities' => MW_EXIF_RATIONAL
, # Chromaticities of primarities
140 'YCbCrCoefficients' => MW_EXIF_RATIONAL
, # Color space transformation matrix coefficients #p27
141 'ReferenceBlackWhite' => MW_EXIF_RATIONAL
# Pair of black and white reference values
146 'DateTime' => MW_EXIF_ASCII
, # File change date and time
147 'ImageDescription' => MW_EXIF_ASCII
, # Image title
148 'Make' => MW_EXIF_ASCII
, # Image input equipment manufacturer
149 'Model' => MW_EXIF_ASCII
, # Image input equipment model
150 'Software' => MW_EXIF_ASCII
, # Software used
151 'Artist' => MW_EXIF_ASCII
, # Person who created the image
152 'Copyright' => MW_EXIF_ASCII
, # Copyright holder
156 # Exif IFD Attribute Information (p30-31)
158 # Tags relating to version
160 # TODO: NOTE: Nonexistence of this field is taken to mean nonconformance
161 # to the EXIF 2.1 AND 2.2 standards
162 'ExifVersion' => MW_EXIF_UNDEFINED
, # Exif version
163 'FlashpixVersion' => MW_EXIF_UNDEFINED
, # Supported Flashpix version #p32
166 # Tags relating to Image Data Characteristics
167 'characteristics' => array(
168 'ColorSpace' => MW_EXIF_SHORT
, # Color space information #p32
171 # Tags relating to image configuration
172 'configuration' => array(
173 'ComponentsConfiguration' => MW_EXIF_UNDEFINED
, # Meaning of each component #p33
174 'CompressedBitsPerPixel' => MW_EXIF_RATIONAL
, # Image compression mode
175 'PixelYDimension' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Valid image width
176 'PixelXDimension' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Valind image height
179 # Tags relating to related user information
181 'MakerNote' => MW_EXIF_UNDEFINED
, # Manufacturer notes
182 'UserComment' => MW_EXIF_UNDEFINED
, # User comments #p34
185 # Tags relating to related file information
187 'RelatedSoundFile' => MW_EXIF_ASCII
, # Related audio file
190 # Tags relating to date and time
191 'dateandtime' => array(
192 'DateTimeOriginal' => MW_EXIF_ASCII
, # Date and time of original data generation #p36
193 'DateTimeDigitized' => MW_EXIF_ASCII
, # Date and time of original data generation
194 'SubSecTime' => MW_EXIF_ASCII
, # DateTime subseconds
195 'SubSecTimeOriginal' => MW_EXIF_ASCII
, # DateTimeOriginal subseconds
196 'SubSecTimeDigitized' => MW_EXIF_ASCII
, # DateTimeDigitized subseconds
199 # Tags relating to picture-taking conditions (p31)
200 'conditions' => array(
201 'ExposureTime' => MW_EXIF_RATIONAL
, # Exposure time
202 'FNumber' => MW_EXIF_RATIONAL
, # F Number
203 'ExposureProgram' => MW_EXIF_SHORT
, # Exposure Program #p38
204 'SpectralSensitivity' => MW_EXIF_ASCII
, # Spectral sensitivity
205 'ISOSpeedRatings' => MW_EXIF_SHORT
, # ISO speed rating
206 'OECF' => MW_EXIF_UNDEFINED
, # Optoelectronic conversion factor
207 'ShutterSpeedValue' => MW_EXIF_SRATIONAL
, # Shutter speed
208 'ApertureValue' => MW_EXIF_RATIONAL
, # Aperture
209 'BrightnessValue' => MW_EXIF_SRATIONAL
, # Brightness
210 'ExposureBiasValue' => MW_EXIF_SRATIONAL
, # Exposure bias
211 'MaxApertureValue' => MW_EXIF_RATIONAL
, # Maximum land aperture
212 'SubjectDistance' => MW_EXIF_RATIONAL
, # Subject distance
213 'MeteringMode' => MW_EXIF_SHORT
, # Metering mode #p40
214 'LightSource' => MW_EXIF_SHORT
, # Light source #p40-41
215 'Flash' => MW_EXIF_SHORT
, # Flash #p41-42
216 'FocalLength' => MW_EXIF_RATIONAL
, # Lens focal length
217 'SubjectArea' => MW_EXIF_SHORT
, # Subject area
218 'FlashEnergy' => MW_EXIF_RATIONAL
, # Flash energy
219 'SpatialFrequencyResponse' => MW_EXIF_UNDEFINED
, # Spatial frequency response
220 'FocalPlaneXResolution' => MW_EXIF_RATIONAL
, # Focal plane X resolution
221 'FocalPlaneYResolution' => MW_EXIF_RATIONAL
, # Focal plane Y resolution
222 'FocalPlaneResolutionUnit' => MW_EXIF_SHORT
, # Focal plane resolution unit #p46
223 'SubjectLocation' => MW_EXIF_SHORT
, # Subject location
224 'ExposureIndex' => MW_EXIF_RATIONAL
, # Exposure index
225 'SensingMethod' => MW_EXIF_SHORT
, # Sensing method #p46
226 'FileSource' => MW_EXIF_UNDEFINED
, # File source #p47
227 'SceneType' => MW_EXIF_UNDEFINED
, # Scene type #p47
228 'CFAPattern' => MW_EXIF_UNDEFINED
, # CFA pattern
229 'CustomRendered' => MW_EXIF_SHORT
, # Custom image processing #p48
230 'ExposureMode' => MW_EXIF_SHORT
, # Exposure mode #p48
231 'WhiteBalance' => MW_EXIF_SHORT
, # White Balance #p49
232 'DigitalZoomRatio' => MW_EXIF_RATIONAL
, # Digital zoom ration
233 'FocalLengthIn35mmFilm' => MW_EXIF_SHORT
, # Focal length in 35 mm film
234 'SceneCaptureType' => MW_EXIF_SHORT
, # Scene capture type #p49
235 'GainControl' => MW_EXIF_RATIONAL
, # Scene control #p49-50
236 'Contrast' => MW_EXIF_SHORT
, # Contrast #p50
237 'Saturation' => MW_EXIF_SHORT
, # Saturation #p50
238 'Sharpness' => MW_EXIF_SHORT
, # Sharpness #p50
239 'DeviceSettingDescription' => MW_EXIF_UNDEFINED
, # Desice settings description
240 'SubjectDistanceRange' => MW_EXIF_SHORT
, # Subject distance range #p51
244 'ImageUniqueID' => MW_EXIF_ASCII
, # Unique image ID
248 # GPS Attribute Information (p52)
250 'GPSVersionID' => MW_EXIF_BYTE
, # GPS tag version
251 'GPSLatitudeRef' => MW_EXIF_ASCII
, # North or South Latitude #p52-53
252 'GPSLatitude' => MW_EXIF_RATIONAL
, # Latitude
253 'GPSLongitudeRef' => MW_EXIF_ASCII
, # East or West Longitude #p53
254 'GPSLongitude' => MW_EXIF_RATIONAL
, # Longitude
255 'GPSAltitudeRef' => MW_EXIF_BYTE
, # Altitude reference
256 'GPSAltitude' => MW_EXIF_RATIONAL
, # Altitude
257 'GPSTimeStamp' => MW_EXIF_RATIONAL
, # GPS time (atomic clock)
258 'GPSSatellites' => MW_EXIF_ASCII
, # Satellites used for measurement
259 'GPSStatus' => MW_EXIF_ASCII
, # Receiver status #p54
260 'GPSMeasureMode' => MW_EXIF_ASCII
, # Measurement mode #p54-55
261 'GPSDOP' => MW_EXIF_RATIONAL
, # Measurement precision
262 'GPSSpeedRef' => MW_EXIF_ASCII
, # Speed unit #p55
263 'GPSSpeed' => MW_EXIF_RATIONAL
, # Speed of GPS receiver
264 'GPSTrackRef' => MW_EXIF_ASCII
, # Reference for direction of movement #p55
265 'GPSTrack' => MW_EXIF_RATIONAL
, # Direction of movement
266 'GPSImgDirectionRef' => MW_EXIF_ASCII
, # Reference for direction of image #p56
267 'GPSImgDirection' => MW_EXIF_RATIONAL
, # Direction of image
268 'GPSMapDatum' => MW_EXIF_ASCII
, # Geodetic survey data used
269 'GPSDestLatitudeRef' => MW_EXIF_ASCII
, # Reference for latitude of destination #p56
270 'GPSDestLatitude' => MW_EXIF_RATIONAL
, # Latitude destination
271 'GPSDestLongitudeRef' => MW_EXIF_ASCII
, # Reference for longitude of destination #p57
272 'GPSDestLongitude' => MW_EXIF_RATIONAL
, # Longitude of destination
273 'GPSDestBearingRef' => MW_EXIF_ASCII
, # Reference for bearing of destination #p57
274 'GPSDestBearing' => MW_EXIF_RATIONAL
, # Bearing of destination
275 'GPSDestDistanceRef' => MW_EXIF_ASCII
, # Reference for distance to destination #p57-58
276 'GPSDestDistance' => MW_EXIF_RATIONAL
, # Distance to destination
277 'GPSProcessingMethod' => MW_EXIF_UNDEFINED
, # Name of GPS processing method
278 'GPSAreaInformation' => MW_EXIF_UNDEFINED
, # Name of GPS area
279 'GPSDateStamp' => MW_EXIF_ASCII
, # GPS date
280 'GPSDifferential' => MW_EXIF_SHORT
, # GPS differential correction
284 $basename = basename( $file );
286 $this->makeFlatExifTags();
288 $this->debugFile( $basename, __FUNCTION__
, true );
289 wfSuppressWarnings();
290 $this->mRawExifData
= exif_read_data( $file );
293 $this->makeFilteredData();
294 $this->makeFormattedData();
296 $this->debugFile( $basename, __FUNCTION__
, false );
303 * Generate a flat list of the exif tags
305 function makeFlatExifTags() {
306 $this->extractTags( $this->mExifTags
);
310 * A recursing extractor function used by makeFlatExifTags()
312 * Note: This used to use an array_walk function, but it made PHP5
313 * segfault, see `cvs diff -u -r 1.4 -r 1.5 Exif.php`
315 function extractTags( &$tagset ) {
316 foreach( $tagset as $key => $val ) {
317 if( is_array( $val ) ) {
318 $this->extractTags( $val );
320 $this->mFlatExifTags
[$key] = $val;
326 * Make $this->mFilteredExifData
328 function makeFilteredData() {
329 $this->mFilteredExifData
= $this->mRawExifData
;
331 foreach( $this->mFilteredExifData
as $k => $v ) {
332 if ( !in_array( $k, array_keys( $this->mFlatExifTags
) ) ) {
333 $this->debug( $v, __FUNCTION__
, "'$k' is not a valid Exif tag" );
334 unset( $this->mFilteredExifData
[$k] );
338 foreach( $this->mFilteredExifData
as $k => $v ) {
339 if ( !$this->validate($k, $v) ) {
340 $this->debug( $v, __FUNCTION__
, "'$k' contained invalid data" );
341 unset( $this->mFilteredExifData
[$k] );
346 function makeFormattedData( $data = null ) {
347 $format = new FormatExif( $this->getFilteredData() );
348 $this->mFormattedExifData
= $format->getFormattedData();
356 * Get $this->mRawExifData
359 return $this->mRawExifData
;
363 * Get $this->mFilteredExifData
365 function getFilteredData() {
366 return $this->mFilteredExifData
;
370 * Get $this->mFormattedExifData
372 function getFormattedData() {
373 return $this->mFormattedExifData
;
378 * The version of the output format
380 * Before the actual metadata information is saved in the database we
381 * strip some of it since we don't want to save things like thumbnails
382 * which usually accompany Exif data. This value gets saved in the
383 * database along with the actual Exif data, and if the version in the
384 * database doesn't equal the value returned by this function the Exif
385 * data is regenerated.
390 return 1; // We don't need no bloddy constants!
394 * Validates if a tag value is of the type it should be according to the Exif spec
398 * @param mixed $in The input value to check
401 function isByte( $in ) {
402 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 255 ) {
403 $this->debug( $in, __FUNCTION__
, true );
406 $this->debug( $in, __FUNCTION__
, false );
411 function isASCII( $in ) {
412 if ( preg_match( "/[^\x0a\x20-\x7e]/", $in ) ) {
413 $this->debug( $in, __FUNCTION__
, 'found a character not in our whitelist' );
417 if ( preg_match( "/^\s*$/", $in ) ) {
418 $this->debug( $in, __FUNCTION__
, 'input consisted solely of whitespace' );
425 function isShort( $in ) {
426 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) {
427 $this->debug( $in, __FUNCTION__
, true );
430 $this->debug( $in, __FUNCTION__
, false );
435 function isLong( $in ) {
436 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) {
437 $this->debug( $in, __FUNCTION__
, true );
440 $this->debug( $in, __FUNCTION__
, false );
445 function isRational( $in ) {
446 if ( @preg_match
( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
447 return $this->isLong( $m[1] ) && $this->isLong( $m[2] );
449 $this->debug( $in, __FUNCTION__
, 'fed a non-fraction value' );
454 function isUndefined( $in ) {
455 if ( preg_match( "/^\d{4}$/", $in ) ) { // Allow ExifVersion and FlashpixVersion
456 $this->debug( $in, __FUNCTION__
, true );
459 $this->debug( $in, __FUNCTION__
, false );
464 function isSlong( $in ) {
465 if ( $this->isLong( abs( $in ) ) ) {
466 $this->debug( $in, __FUNCTION__
, true );
469 $this->debug( $in, __FUNCTION__
, false );
474 function isSrational( $in ) {
475 if ( preg_match( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
476 return $this->isSlong( $m[0] ) && $this->isSlong( $m[1] );
478 $this->debug( $in, __FUNCTION__
, 'fed a non-fraction value' );
485 * Validates if a tag has a legal value according to the Exif spec
489 * @param string $tag The tag to check
490 * @param mixed $val The value of the tag
493 function validate( $tag, $val ) {
494 $debug = "tag is '$tag'";
495 // Fucks up if not typecast
496 switch( (string)$this->mFlatExifTags
[$tag] ) {
497 case (string)MW_EXIF_BYTE
:
498 $this->debug( $val, __FUNCTION__
, $debug );
499 return $this->isByte( $val );
500 case (string)MW_EXIF_ASCII
:
501 $this->debug( $val, __FUNCTION__
, $debug );
502 return $this->isASCII( $val );
503 case (string)MW_EXIF_SHORT
:
504 $this->debug( $val, __FUNCTION__
, $debug );
505 return $this->isShort( $val );
506 case (string)MW_EXIF_LONG
:
507 $this->debug( $val, __FUNCTION__
, $debug );
508 return $this->isLong( $val );
509 case (string)MW_EXIF_RATIONAL
:
510 $this->debug( $val, __FUNCTION__
, $debug );
511 return $this->isRational( $val );
512 case (string)MW_EXIF_UNDEFINED
:
513 $this->debug( $val, __FUNCTION__
, $debug );
514 return $this->isUndefined( $val );
515 case (string)MW_EXIF_SLONG
:
516 $this->debug( $val, __FUNCTION__
, $debug );
517 return $this->isSlong( $val );
518 case (string)MW_EXIF_SRATIONAL
:
519 $this->debug( $val, __FUNCTION__
, $debug );
520 return $this->isSrational( $val );
521 case (string)MW_EXIF_SHORT
.','.MW_EXIF_LONG
:
522 $this->debug( $val, __FUNCTION__
, $debug );
523 return $this->isShort( $val ) ||
$this->isLong( $val );
525 $this->debug( $val, __FUNCTION__
, "The tag '$tag' is unknown" );
531 * Conviniance function for debugging output
536 * @param string $fname
537 * @param mixed $action
539 function debug( $in, $fname, $action = null ) {
540 $type = gettype( $in );
541 $class = ucfirst( __CLASS__
);
542 if ( $type === 'array' )
543 $in = print_r( $in, true );
545 if ( $action === true )
546 wfDebugLog( $this->log
, "$class::$fname: accepted: '$in' (type: $type)\n");
547 elseif ( $action === false )
548 wfDebugLog( $this->log
, "$class::$fname: rejected: '$in' (type: $type)\n");
549 elseif ( $action === null )
550 wfDebugLog( $this->log
, "$class::$fname: input was: '$in' (type: $type)\n");
552 wfDebugLog( $this->log
, "$class::$fname: $action (type: $type; content: '$in')\n");
556 * Conviniance function for debugging output
560 * @param string $basename The name of the file being processed
561 * @paran string $fname The name of the function calling this function
562 * @param bool $bool $io Specify whether we're beginning or ending
564 function debugFile( $basename, $fname, $io ) {
565 $class = ucfirst( __CLASS__
);
567 wfDebugLog( $this->log
, "$class::$fname: begin processing: '$basename'\n" );
569 wfDebugLog( $this->log
, "$class::$fname: end processing: '$basename'\n" );
576 * @subpackage Metadata
580 * The Exif data to format
590 * @param array $exif The Exif data to format ( as returned by
591 * Exif::getFilteredData() )
593 function FormatExif( $exif ) {
594 $this->mExif
= $exif;
598 * Numbers given by Exif user agents are often magical, that is they
599 * should be replaced by a detailed explanation depending on their
600 * value which most of the time are plain integers. This function
601 * formats Exif values into human readable form.
605 function getFormattedData() {
608 $tags =& $this->mExif
;
610 $resolutionunit = !isset( $tags['ResolutionUnit'] ) ||
$tags['ResolutionUnit'] == 2 ?
2 : 3;
611 unset( $tags['ResolutionUnit'] );
613 foreach( $tags as $tag => $val ) {
618 $tags[$tag] = $this->msg( $tag, $val );
626 case 'PhotometricInterpretation':
629 $tags[$tag] = $this->msg( $tag, $val );
639 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
640 $tags[$tag] = $this->msg( $tag, $val );
648 case 'PlanarConfiguration':
651 $tags[$tag] = $this->msg( $tag, $val );
659 // TODO: YCbCrSubSampling
660 // TODO: YCbCrPositioning
664 switch( $resolutionunit ) {
666 $tags[$tag] = $this->msg( 'XYResolution', 'i', $this->formatNum( $val ) );
669 $this->msg( 'XYResolution', 'c', $this->formatNum( $val ) );
677 // TODO: YCbCrCoefficients #p27 (see annex E)
678 case 'ExifVersion': case 'FlashpixVersion':
679 $tags[$tag] = "$val"/100;
684 case 1: case 'FFFF.H':
685 $tags[$tag] = $this->msg( $tag, $val );
693 case 'ComponentsConfiguration':
695 case 0: case 1: case 2: case 3: case 4: case 5: case 6:
696 $tags[$tag] = $this->msg( $tag, $val );
705 case 'DateTimeOriginal':
706 case 'DateTimeDigitized':
707 $tags[$tag] = $wgLang->timeanddate( wfTimestamp(TS_MW
, $val) );
710 case 'ExposureProgram':
712 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
713 $tags[$tag] = $this->msg( $tag, $val );
721 case 'SubjectDistance':
722 $tags[$tag] = $this->msg( $tag, '', $this->formatNum( $val ) );
727 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 255:
728 $tags[$tag] = $this->msg( $tag, $val );
738 case 0: case 1: case 2: case 3: case 4: case 9: case 10: case 11:
739 case 12: case 13: case 14: case 15: case 17: case 18: case 19: case 20:
740 case 21: case 22: case 23: case 24: case 255:
741 $tags[$tag] = $this->msg( $tag, $val );
750 case 'FocalPlaneResolutionUnit':
753 $tags[$tag] = $this->msg( $tag, $val );
761 case 'SensingMethod':
763 case 1: case 2: case 3: case 4: case 5: case 7: case 8:
764 $tags[$tag] = $this->msg( $tag, $val );
775 $tags[$tag] = $this->msg( $tag, $val );
786 $tags[$tag] = $this->msg( $tag, $val );
794 case 'CustomRendered':
797 $tags[$tag] = $this->msg( $tag, $val );
807 case 0: case 1: case 2:
808 $tags[$tag] = $this->msg( $tag, $val );
819 $tags[$tag] = $this->msg( $tag, $val );
827 case 'SceneCaptureType':
829 case 0: case 1: case 2: case 3:
830 $tags[$tag] = $this->msg( $tag, $val );
840 case 0: case 1: case 2: case 3: case 4:
841 $tags[$tag] = $this->msg( $tag, $val );
851 case 0: case 1: case 2:
852 $tags[$tag] = $this->msg( $tag, $val );
862 case 0: case 1: case 2:
863 $tags[$tag] = $this->msg( $tag, $val );
873 case 0: case 1: case 2:
874 $tags[$tag] = $this->msg( $tag, $val );
882 case 'SubjectDistanceRange':
884 case 0: case 1: case 2: case 3:
885 $tags[$tag] = $this->msg( $tag, $val );
893 case 'GPSLatitudeRef':
894 case 'GPSDestLatitudeRef':
897 $tags[$tag] = $this->msg( 'GPSLatitude', $val );
905 case 'GPSLongitudeRef':
906 case 'GPSDestLongitudeRef':
909 $tags[$tag] = $this->msg( 'GPSLongitude', $val );
920 $tags[$tag] = $this->msg( $tag, $val );
928 case 'GPSMeasureMode':
931 $tags[$tag] = $this->msg( $tag, $val );
940 case 'GPSDestDistanceRef':
942 case 'K': case 'M': case 'N':
943 $tags[$tag] = $this->msg( 'GPSSpeed', $val );
952 case 'GPSImgDirectionRef':
953 case 'GPSDestBearingRef':
956 $tags[$tag] = $this->msg( 'GPSDirection', $val );
965 $tags[$tag] = $wgLang->date( substr( $val, 0, 4 ) . substr( $val, 5, 2 ) . substr( $val, 8, 2 ) . '000000' );
968 // This is not in the Exif standard, just a special
969 // case for our purposes which enables wikis to wikify
970 // the make, model and software name to link to their articles.
974 $tags[$tag] = $this->msg( $tag, '', $val );
977 $tags[$tag] = $this->formatNum( $val );
986 * Conviniance function for getFormattedData()
990 * @param string $tag The tag name to pass on
991 * @param string $val The value of the tag
992 * @param string $arg An argument to pass ($1)
993 * @return string A wfMsg of "exif-$tag-$val" in lower case
995 function msg( $tag, $val, $arg = null ) {
998 return wfMsg( strtolower( "exif-$tag-$val" ), $arg );
1002 * Format a number, convert numbers from fractions into floating point
1007 * @param mixed $num The value to format
1008 * @return mixed A floating point number or whatever we were fed
1010 function formatNum( $num ) {
1011 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) )
1012 return $m[2] != 0 ?
$m[1] / $m[2] : $num;