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 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * http://www.gnu.org/copyleft/gpl.html
25 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
30 * Exif tag type definition
32 define('MW_EXIF_BYTE', 1); # An 8-bit (1-byte) unsigned integer.
33 define('MW_EXIF_ASCII', 2); # An 8-bit byte containing one 7-bit ASCII code. The final byte is terminated with NULL.
34 define('MW_EXIF_SHORT', 3); # A 16-bit (2-byte) unsigned integer.
35 define('MW_EXIF_LONG', 4); # A 32-bit (4-byte) unsigned integer.
36 define('MW_EXIF_RATIONAL', 5); # Two LONGs. The first LONG is the numerator and the second LONG expresses the denominator
37 define('MW_EXIF_UNDEFINED', 7); # An 8-bit byte that can take any value depending on the field definition
38 define('MW_EXIF_SLONG', 9); # A 32-bit (4-byte) signed integer (2's complement notation),
39 define('MW_EXIF_SRATIONAL', 10); # Two SLONGs. The first SLONG is the numerator and the second SLONG is the denominator.
45 * @subpackage Metadata
54 * Exif tags grouped by category, the tagname itself is the key and the type
55 * is the value, in the case of more than one possible value type they are
56 * seperated by commas.
61 * A one dimentional array of all Exif tags
66 * The raw Exif data returned by exif_read_data()
71 * A Filtered version of $mRawExifData that has been pruned of invalid
72 * tags and tags that contain content they shouldn't contain according
73 * to the Exif specification
75 var $mFilteredExifData;
78 * Filtered and formatted Exif data, see FormatExif::getFormattedData()
80 var $mFormattedExifData;
90 * The file being processed
95 * The basename of the file being processed
100 * The private log to log to
109 * @param string $file
111 function Exif( $file ) {
113 * Page numbers here refer to pages in the EXIF 2.2 standard
115 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
117 $this->mExifTags
= array(
118 # TIFF Rev. 6.0 Attribute Information (p22)
120 # Tags relating to image structure
121 'structure' => array(
122 'ImageWidth' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Image width
123 'ImageLength' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Image height
124 'BitsPerSample' => MW_EXIF_SHORT
, # Number of bits per component
125 # "When a primary image is JPEG compressed, this designation is not"
126 # "necessary and is omitted." (p23)
127 'Compression' => MW_EXIF_SHORT
, # Compression scheme #p23
128 'PhotometricInterpretation' => MW_EXIF_SHORT
, # Pixel composition #p23
129 'Orientation' => MW_EXIF_SHORT
, # Orientation of image #p24
130 'SamplesPerPixel' => MW_EXIF_SHORT
, # Number of components
131 'PlanarConfiguration' => MW_EXIF_SHORT
, # Image data arrangement #p24
132 'YCbCrSubSampling' => MW_EXIF_SHORT
, # Subsampling ratio of Y to C #p24
133 'YCbCrPositioning' => MW_EXIF_SHORT
, # Y and C positioning #p24-25
134 'XResolution' => MW_EXIF_RATIONAL
, # Image resolution in width direction
135 'YResolution' => MW_EXIF_RATIONAL
, # Image resolution in height direction
136 'ResolutionUnit' => MW_EXIF_SHORT
, # Unit of X and Y resolution #(p26)
139 # Tags relating to recording offset
141 'StripOffsets' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Image data location
142 'RowsPerStrip' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Number of rows per strip
143 'StripByteCounts' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Bytes per compressed strip
144 'JPEGInterchangeFormat' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Offset to JPEG SOI
145 'JPEGInterchangeFormatLength' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Bytes of JPEG data
148 # Tags relating to image data characteristics
149 'characteristics' => array(
150 'TransferFunction' => MW_EXIF_SHORT
, # Transfer function
151 'WhitePoint' => MW_EXIF_RATIONAL
, # White point chromaticity
152 'PrimaryChromaticities' => MW_EXIF_RATIONAL
, # Chromaticities of primarities
153 'YCbCrCoefficients' => MW_EXIF_RATIONAL
, # Color space transformation matrix coefficients #p27
154 'ReferenceBlackWhite' => MW_EXIF_RATIONAL
# Pair of black and white reference values
159 'DateTime' => MW_EXIF_ASCII
, # File change date and time
160 'ImageDescription' => MW_EXIF_ASCII
, # Image title
161 'Make' => MW_EXIF_ASCII
, # Image input equipment manufacturer
162 'Model' => MW_EXIF_ASCII
, # Image input equipment model
163 'Software' => MW_EXIF_ASCII
, # Software used
164 'Artist' => MW_EXIF_ASCII
, # Person who created the image
165 'Copyright' => MW_EXIF_ASCII
, # Copyright holder
169 # Exif IFD Attribute Information (p30-31)
171 # Tags relating to version
173 # TODO: NOTE: Nonexistence of this field is taken to mean nonconformance
174 # to the EXIF 2.1 AND 2.2 standards
175 'ExifVersion' => MW_EXIF_UNDEFINED
, # Exif version
176 'FlashpixVersion' => MW_EXIF_UNDEFINED
, # Supported Flashpix version #p32
179 # Tags relating to Image Data Characteristics
180 'characteristics' => array(
181 'ColorSpace' => MW_EXIF_SHORT
, # Color space information #p32
184 # Tags relating to image configuration
185 'configuration' => array(
186 'ComponentsConfiguration' => MW_EXIF_UNDEFINED
, # Meaning of each component #p33
187 'CompressedBitsPerPixel' => MW_EXIF_RATIONAL
, # Image compression mode
188 'PixelYDimension' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Valid image width
189 'PixelXDimension' => MW_EXIF_SHORT
.','.MW_EXIF_LONG
, # Valind image height
192 # Tags relating to related user information
194 'MakerNote' => MW_EXIF_UNDEFINED
, # Manufacturer notes
195 'UserComment' => MW_EXIF_UNDEFINED
, # User comments #p34
198 # Tags relating to related file information
200 'RelatedSoundFile' => MW_EXIF_ASCII
, # Related audio file
203 # Tags relating to date and time
204 'dateandtime' => array(
205 'DateTimeOriginal' => MW_EXIF_ASCII
, # Date and time of original data generation #p36
206 'DateTimeDigitized' => MW_EXIF_ASCII
, # Date and time of original data generation
207 'SubSecTime' => MW_EXIF_ASCII
, # DateTime subseconds
208 'SubSecTimeOriginal' => MW_EXIF_ASCII
, # DateTimeOriginal subseconds
209 'SubSecTimeDigitized' => MW_EXIF_ASCII
, # DateTimeDigitized subseconds
212 # Tags relating to picture-taking conditions (p31)
213 'conditions' => array(
214 'ExposureTime' => MW_EXIF_RATIONAL
, # Exposure time
215 'FNumber' => MW_EXIF_RATIONAL
, # F Number
216 'ExposureProgram' => MW_EXIF_SHORT
, # Exposure Program #p38
217 'SpectralSensitivity' => MW_EXIF_ASCII
, # Spectral sensitivity
218 'ISOSpeedRatings' => MW_EXIF_SHORT
, # ISO speed rating
219 'OECF' => MW_EXIF_UNDEFINED
, # Optoelectronic conversion factor
220 'ShutterSpeedValue' => MW_EXIF_SRATIONAL
, # Shutter speed
221 'ApertureValue' => MW_EXIF_RATIONAL
, # Aperture
222 'BrightnessValue' => MW_EXIF_SRATIONAL
, # Brightness
223 'ExposureBiasValue' => MW_EXIF_SRATIONAL
, # Exposure bias
224 'MaxApertureValue' => MW_EXIF_RATIONAL
, # Maximum land aperture
225 'SubjectDistance' => MW_EXIF_RATIONAL
, # Subject distance
226 'MeteringMode' => MW_EXIF_SHORT
, # Metering mode #p40
227 'LightSource' => MW_EXIF_SHORT
, # Light source #p40-41
228 'Flash' => MW_EXIF_SHORT
, # Flash #p41-42
229 'FocalLength' => MW_EXIF_RATIONAL
, # Lens focal length
230 'SubjectArea' => MW_EXIF_SHORT
, # Subject area
231 'FlashEnergy' => MW_EXIF_RATIONAL
, # Flash energy
232 'SpatialFrequencyResponse' => MW_EXIF_UNDEFINED
, # Spatial frequency response
233 'FocalPlaneXResolution' => MW_EXIF_RATIONAL
, # Focal plane X resolution
234 'FocalPlaneYResolution' => MW_EXIF_RATIONAL
, # Focal plane Y resolution
235 'FocalPlaneResolutionUnit' => MW_EXIF_SHORT
, # Focal plane resolution unit #p46
236 'SubjectLocation' => MW_EXIF_SHORT
, # Subject location
237 'ExposureIndex' => MW_EXIF_RATIONAL
, # Exposure index
238 'SensingMethod' => MW_EXIF_SHORT
, # Sensing method #p46
239 'FileSource' => MW_EXIF_UNDEFINED
, # File source #p47
240 'SceneType' => MW_EXIF_UNDEFINED
, # Scene type #p47
241 'CFAPattern' => MW_EXIF_UNDEFINED
, # CFA pattern
242 'CustomRendered' => MW_EXIF_SHORT
, # Custom image processing #p48
243 'ExposureMode' => MW_EXIF_SHORT
, # Exposure mode #p48
244 'WhiteBalance' => MW_EXIF_SHORT
, # White Balance #p49
245 'DigitalZoomRatio' => MW_EXIF_RATIONAL
, # Digital zoom ration
246 'FocalLengthIn35mmFilm' => MW_EXIF_SHORT
, # Focal length in 35 mm film
247 'SceneCaptureType' => MW_EXIF_SHORT
, # Scene capture type #p49
248 'GainControl' => MW_EXIF_RATIONAL
, # Scene control #p49-50
249 'Contrast' => MW_EXIF_SHORT
, # Contrast #p50
250 'Saturation' => MW_EXIF_SHORT
, # Saturation #p50
251 'Sharpness' => MW_EXIF_SHORT
, # Sharpness #p50
252 'DeviceSettingDescription' => MW_EXIF_UNDEFINED
, # Desice settings description
253 'SubjectDistanceRange' => MW_EXIF_SHORT
, # Subject distance range #p51
257 'ImageUniqueID' => MW_EXIF_ASCII
, # Unique image ID
261 # GPS Attribute Information (p52)
263 'GPSVersionID' => MW_EXIF_BYTE
, # GPS tag version
264 'GPSLatitudeRef' => MW_EXIF_ASCII
, # North or South Latitude #p52-53
265 'GPSLatitude' => MW_EXIF_RATIONAL
, # Latitude
266 'GPSLongitudeRef' => MW_EXIF_ASCII
, # East or West Longitude #p53
267 'GPSLongitude' => MW_EXIF_RATIONAL
, # Longitude
268 'GPSAltitudeRef' => MW_EXIF_BYTE
, # Altitude reference
269 'GPSAltitude' => MW_EXIF_RATIONAL
, # Altitude
270 'GPSTimeStamp' => MW_EXIF_RATIONAL
, # GPS time (atomic clock)
271 'GPSSatellites' => MW_EXIF_ASCII
, # Satellites used for measurement
272 'GPSStatus' => MW_EXIF_ASCII
, # Receiver status #p54
273 'GPSMeasureMode' => MW_EXIF_ASCII
, # Measurement mode #p54-55
274 'GPSDOP' => MW_EXIF_RATIONAL
, # Measurement precision
275 'GPSSpeedRef' => MW_EXIF_ASCII
, # Speed unit #p55
276 'GPSSpeed' => MW_EXIF_RATIONAL
, # Speed of GPS receiver
277 'GPSTrackRef' => MW_EXIF_ASCII
, # Reference for direction of movement #p55
278 'GPSTrack' => MW_EXIF_RATIONAL
, # Direction of movement
279 'GPSImgDirectionRef' => MW_EXIF_ASCII
, # Reference for direction of image #p56
280 'GPSImgDirection' => MW_EXIF_RATIONAL
, # Direction of image
281 'GPSMapDatum' => MW_EXIF_ASCII
, # Geodetic survey data used
282 'GPSDestLatitudeRef' => MW_EXIF_ASCII
, # Reference for latitude of destination #p56
283 'GPSDestLatitude' => MW_EXIF_RATIONAL
, # Latitude destination
284 'GPSDestLongitudeRef' => MW_EXIF_ASCII
, # Reference for longitude of destination #p57
285 'GPSDestLongitude' => MW_EXIF_RATIONAL
, # Longitude of destination
286 'GPSDestBearingRef' => MW_EXIF_ASCII
, # Reference for bearing of destination #p57
287 'GPSDestBearing' => MW_EXIF_RATIONAL
, # Bearing of destination
288 'GPSDestDistanceRef' => MW_EXIF_ASCII
, # Reference for distance to destination #p57-58
289 'GPSDestDistance' => MW_EXIF_RATIONAL
, # Distance to destination
290 'GPSProcessingMethod' => MW_EXIF_UNDEFINED
, # Name of GPS processing method
291 'GPSAreaInformation' => MW_EXIF_UNDEFINED
, # Name of GPS area
292 'GPSDateStamp' => MW_EXIF_ASCII
, # GPS date
293 'GPSDifferential' => MW_EXIF_SHORT
, # GPS differential correction
298 $this->basename
= basename( $this->file
);
300 $this->makeFlatExifTags();
302 $this->debugFile( $this->basename
, __FUNCTION__
, true );
303 wfSuppressWarnings();
304 $data = exif_read_data( $this->file
);
307 * exif_read_data() will return false on invalid input, such as
308 * when somebody uploads a file called something.jpeg
309 * containing random gibberish.
311 $this->mRawExifData
= $data ?
$data : array();
313 $this->makeFilteredData();
314 $this->makeFormattedData();
316 $this->debugFile( __FUNCTION__
, false );
323 * Generate a flat list of the exif tags
325 function makeFlatExifTags() {
326 $this->extractTags( $this->mExifTags
);
330 * A recursing extractor function used by makeFlatExifTags()
332 * Note: This used to use an array_walk function, but it made PHP5
333 * segfault, see `cvs diff -u -r 1.4 -r 1.5 Exif.php`
335 function extractTags( &$tagset ) {
336 foreach( $tagset as $key => $val ) {
337 if( is_array( $val ) ) {
338 $this->extractTags( $val );
340 $this->mFlatExifTags
[$key] = $val;
346 * Make $this->mFilteredExifData
348 function makeFilteredData() {
349 $this->mFilteredExifData
= $this->mRawExifData
;
351 foreach( $this->mFilteredExifData
as $k => $v ) {
352 if ( !in_array( $k, array_keys( $this->mFlatExifTags
) ) ) {
353 $this->debug( $v, __FUNCTION__
, "'$k' is not a valid Exif tag" );
354 unset( $this->mFilteredExifData
[$k] );
358 foreach( $this->mFilteredExifData
as $k => $v ) {
359 if ( !$this->validate($k, $v) ) {
360 $this->debug( $v, __FUNCTION__
, "'$k' contained invalid data" );
361 unset( $this->mFilteredExifData
[$k] );
366 function makeFormattedData( $data = null ) {
367 $format = new FormatExif( $this->getFilteredData() );
368 $this->mFormattedExifData
= $format->getFormattedData();
376 * Get $this->mRawExifData
379 return $this->mRawExifData
;
383 * Get $this->mFilteredExifData
385 function getFilteredData() {
386 return $this->mFilteredExifData
;
390 * Get $this->mFormattedExifData
392 function getFormattedData() {
393 return $this->mFormattedExifData
;
398 * The version of the output format
400 * Before the actual metadata information is saved in the database we
401 * strip some of it since we don't want to save things like thumbnails
402 * which usually accompany Exif data. This value gets saved in the
403 * database along with the actual Exif data, and if the version in the
404 * database doesn't equal the value returned by this function the Exif
405 * data is regenerated.
410 return 1; // We don't need no bloddy constants!
414 * Validates if a tag value is of the type it should be according to the Exif spec
418 * @param mixed $in The input value to check
421 function isByte( $in ) {
422 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 255 ) {
423 $this->debug( $in, __FUNCTION__
, true );
426 $this->debug( $in, __FUNCTION__
, false );
431 function isASCII( $in ) {
432 if ( preg_match( "/[^\x0a\x20-\x7e]/", $in ) ) {
433 $this->debug( $in, __FUNCTION__
, 'found a character not in our whitelist' );
437 if ( preg_match( "/^\s*$/", $in ) ) {
438 $this->debug( $in, __FUNCTION__
, 'input consisted solely of whitespace' );
445 function isShort( $in ) {
446 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) {
447 $this->debug( $in, __FUNCTION__
, true );
450 $this->debug( $in, __FUNCTION__
, false );
455 function isLong( $in ) {
456 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) {
457 $this->debug( $in, __FUNCTION__
, true );
460 $this->debug( $in, __FUNCTION__
, false );
465 function isRational( $in ) {
466 if ( @preg_match
( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
467 return $this->isLong( $m[1] ) && $this->isLong( $m[2] );
469 $this->debug( $in, __FUNCTION__
, 'fed a non-fraction value' );
474 function isUndefined( $in ) {
475 if ( preg_match( "/^\d{4}$/", $in ) ) { // Allow ExifVersion and FlashpixVersion
476 $this->debug( $in, __FUNCTION__
, true );
479 $this->debug( $in, __FUNCTION__
, false );
484 function isSlong( $in ) {
485 if ( $this->isLong( abs( $in ) ) ) {
486 $this->debug( $in, __FUNCTION__
, true );
489 $this->debug( $in, __FUNCTION__
, false );
494 function isSrational( $in ) {
495 if ( preg_match( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
496 return $this->isSlong( $m[0] ) && $this->isSlong( $m[1] );
498 $this->debug( $in, __FUNCTION__
, 'fed a non-fraction value' );
505 * Validates if a tag has a legal value according to the Exif spec
509 * @param string $tag The tag to check
510 * @param mixed $val The value of the tag
513 function validate( $tag, $val ) {
514 $debug = "tag is '$tag'";
515 // Fucks up if not typecast
516 switch( (string)$this->mFlatExifTags
[$tag] ) {
517 case (string)MW_EXIF_BYTE
:
518 $this->debug( $val, __FUNCTION__
, $debug );
519 return $this->isByte( $val );
520 case (string)MW_EXIF_ASCII
:
521 $this->debug( $val, __FUNCTION__
, $debug );
522 return $this->isASCII( $val );
523 case (string)MW_EXIF_SHORT
:
524 $this->debug( $val, __FUNCTION__
, $debug );
525 return $this->isShort( $val );
526 case (string)MW_EXIF_LONG
:
527 $this->debug( $val, __FUNCTION__
, $debug );
528 return $this->isLong( $val );
529 case (string)MW_EXIF_RATIONAL
:
530 $this->debug( $val, __FUNCTION__
, $debug );
531 return $this->isRational( $val );
532 case (string)MW_EXIF_UNDEFINED
:
533 $this->debug( $val, __FUNCTION__
, $debug );
534 return $this->isUndefined( $val );
535 case (string)MW_EXIF_SLONG
:
536 $this->debug( $val, __FUNCTION__
, $debug );
537 return $this->isSlong( $val );
538 case (string)MW_EXIF_SRATIONAL
:
539 $this->debug( $val, __FUNCTION__
, $debug );
540 return $this->isSrational( $val );
541 case (string)MW_EXIF_SHORT
.','.MW_EXIF_LONG
:
542 $this->debug( $val, __FUNCTION__
, $debug );
543 return $this->isShort( $val ) ||
$this->isLong( $val );
545 $this->debug( $val, __FUNCTION__
, "The tag '$tag' is unknown" );
551 * Conviniance function for debugging output
556 * @param string $fname
557 * @param mixed $action
559 function debug( $in, $fname, $action = null ) {
560 $type = gettype( $in );
561 $class = ucfirst( __CLASS__
);
562 if ( $type === 'array' )
563 $in = print_r( $in, true );
565 if ( $action === true )
566 wfDebugLog( $this->log
, "$class::$fname: accepted: '$in' (type: $type)\n");
567 elseif ( $action === false )
568 wfDebugLog( $this->log
, "$class::$fname: rejected: '$in' (type: $type)\n");
569 elseif ( $action === null )
570 wfDebugLog( $this->log
, "$class::$fname: input was: '$in' (type: $type)\n");
572 wfDebugLog( $this->log
, "$class::$fname: $action (type: $type; content: '$in')\n");
576 * Conviniance function for debugging output
580 * @param string $basename The name of the file being processed
581 * @paran string $fname The name of the function calling this function
582 * @param bool $bool $io 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" );
596 * @subpackage Metadata
600 * The Exif data to format
610 * @param array $exif The Exif data to format ( as returned by
611 * Exif::getFilteredData() )
613 function FormatExif( $exif ) {
614 $this->mExif
= $exif;
618 * Numbers given by Exif user agents are often magical, that is they
619 * should be replaced by a detailed explanation depending on their
620 * value which most of the time are plain integers. This function
621 * formats Exif values into human readable form.
625 function getFormattedData() {
628 $tags =& $this->mExif
;
630 $resolutionunit = !isset( $tags['ResolutionUnit'] ) ||
$tags['ResolutionUnit'] == 2 ?
2 : 3;
631 unset( $tags['ResolutionUnit'] );
633 foreach( $tags as $tag => $val ) {
638 $tags[$tag] = $this->msg( $tag, $val );
646 case 'PhotometricInterpretation':
649 $tags[$tag] = $this->msg( $tag, $val );
659 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
660 $tags[$tag] = $this->msg( $tag, $val );
668 case 'PlanarConfiguration':
671 $tags[$tag] = $this->msg( $tag, $val );
679 // TODO: YCbCrSubSampling
680 // TODO: YCbCrPositioning
684 switch( $resolutionunit ) {
686 $tags[$tag] = $this->msg( 'XYResolution', 'i', $this->formatNum( $val ) );
689 $this->msg( 'XYResolution', 'c', $this->formatNum( $val ) );
697 // TODO: YCbCrCoefficients #p27 (see annex E)
698 case 'ExifVersion': case 'FlashpixVersion':
699 $tags[$tag] = "$val"/100;
704 case 1: case 'FFFF.H':
705 $tags[$tag] = $this->msg( $tag, $val );
713 case 'ComponentsConfiguration':
715 case 0: case 1: case 2: case 3: case 4: case 5: case 6:
716 $tags[$tag] = $this->msg( $tag, $val );
725 case 'DateTimeOriginal':
726 case 'DateTimeDigitized':
727 if( preg_match( "/^(\d{4}):(\d\d):(\d\d) (\d\d):(\d\d):(\d\d)$/", $val ) ) {
728 $tags[$tag] = $wgLang->timeanddate( wfTimestamp(TS_MW
, $val) );
732 case 'ExposureProgram':
734 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
735 $tags[$tag] = $this->msg( $tag, $val );
743 case 'SubjectDistance':
744 $tags[$tag] = $this->msg( $tag, '', $this->formatNum( $val ) );
749 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 255:
750 $tags[$tag] = $this->msg( $tag, $val );
760 case 0: case 1: case 2: case 3: case 4: case 9: case 10: case 11:
761 case 12: case 13: case 14: case 15: case 17: case 18: case 19: case 20:
762 case 21: case 22: case 23: case 24: case 255:
763 $tags[$tag] = $this->msg( $tag, $val );
772 case 'FocalPlaneResolutionUnit':
775 $tags[$tag] = $this->msg( $tag, $val );
783 case 'SensingMethod':
785 case 1: case 2: case 3: case 4: case 5: case 7: case 8:
786 $tags[$tag] = $this->msg( $tag, $val );
797 $tags[$tag] = $this->msg( $tag, $val );
808 $tags[$tag] = $this->msg( $tag, $val );
816 case 'CustomRendered':
819 $tags[$tag] = $this->msg( $tag, $val );
829 case 0: case 1: case 2:
830 $tags[$tag] = $this->msg( $tag, $val );
841 $tags[$tag] = $this->msg( $tag, $val );
849 case 'SceneCaptureType':
851 case 0: case 1: case 2: case 3:
852 $tags[$tag] = $this->msg( $tag, $val );
862 case 0: case 1: case 2: case 3: case 4:
863 $tags[$tag] = $this->msg( $tag, $val );
873 case 0: case 1: case 2:
874 $tags[$tag] = $this->msg( $tag, $val );
884 case 0: case 1: case 2:
885 $tags[$tag] = $this->msg( $tag, $val );
895 case 0: case 1: case 2:
896 $tags[$tag] = $this->msg( $tag, $val );
904 case 'SubjectDistanceRange':
906 case 0: case 1: case 2: case 3:
907 $tags[$tag] = $this->msg( $tag, $val );
915 case 'GPSLatitudeRef':
916 case 'GPSDestLatitudeRef':
919 $tags[$tag] = $this->msg( 'GPSLatitude', $val );
927 case 'GPSLongitudeRef':
928 case 'GPSDestLongitudeRef':
931 $tags[$tag] = $this->msg( 'GPSLongitude', $val );
942 $tags[$tag] = $this->msg( $tag, $val );
950 case 'GPSMeasureMode':
953 $tags[$tag] = $this->msg( $tag, $val );
962 case 'GPSDestDistanceRef':
964 case 'K': case 'M': case 'N':
965 $tags[$tag] = $this->msg( 'GPSSpeed', $val );
974 case 'GPSImgDirectionRef':
975 case 'GPSDestBearingRef':
978 $tags[$tag] = $this->msg( 'GPSDirection', $val );
987 $tags[$tag] = $wgLang->date( substr( $val, 0, 4 ) . substr( $val, 5, 2 ) . substr( $val, 8, 2 ) . '000000' );
990 // This is not in the Exif standard, just a special
991 // case for our purposes which enables wikis to wikify
992 // the make, model and software name to link to their articles.
996 $tags[$tag] = $this->msg( $tag, '', $val );
1000 // Show the pretty fraction as well as decimal version
1001 $tags[$tag] = wfMsg( 'exif-exposuretime-format',
1002 $this->formatFraction( $val ), $this->formatNum( $val ) );
1006 $tags[$tag] = wfMsg( 'exif-fnumber-format',
1007 $this->formatNum( $val ) );
1011 $tags[$tag] = wfMsg( 'exif-focallength-format',
1012 $this->formatNum( $val ) );
1016 $tags[$tag] = $this->formatNum( $val );
1025 * Conviniance function for getFormattedData()
1029 * @param string $tag The tag name to pass on
1030 * @param string $val The value of the tag
1031 * @param string $arg An argument to pass ($1)
1032 * @return string A wfMsg of "exif-$tag-$val" in lower case
1034 function msg( $tag, $val, $arg = null ) {
1039 return wfMsg( $wgContLang->lc( "exif-$tag-$val" ), $arg );
1043 * Format a number, convert numbers from fractions into floating point
1048 * @param mixed $num The value to format
1049 * @return mixed A floating point number or whatever we were fed
1051 function formatNum( $num ) {
1052 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) )
1053 return $m[2] != 0 ?
$m[1] / $m[2] : $num;
1059 * Format a rational number, reducing fractions
1063 * @param mixed $num The value to format
1064 * @return mixed A floating point number or whatever we were fed
1066 function formatFraction( $num ) {
1067 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) ) {
1068 $numerator = intval( $m[1] );
1069 $denominator = intval( $m[2] );
1070 $gcd = $this->gcd( $numerator, $denominator );
1072 // 0 shouldn't happen! ;)
1073 return $numerator / $gcd . '/' . $denominator / $gcd;
1076 return $this->formatNum( $num );
1080 * Calculate the greatest common divisor of two integers.
1087 function gcd( $a, $b ) {
1089 // http://en.wikipedia.org/wiki/Euclidean_algorithm
1090 // Recursive form would be:
1094 return gcd( $b, $a % $b );
1097 $remainder = $a %
$b;
1099 // tail recursion...