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
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 $file String: filename.
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] );
369 function makeFormattedData( $data = null ) {
370 $format = new FormatExif( $this->getFilteredData() );
371 $this->mFormattedExifData
= $format->getFormattedData();
379 * Get $this->mRawExifData
382 return $this->mRawExifData
;
386 * Get $this->mFilteredExifData
388 function getFilteredData() {
389 return $this->mFilteredExifData
;
393 * Get $this->mFormattedExifData
395 function getFormattedData() {
396 return $this->mFormattedExifData
;
401 * The version of the output format
403 * Before the actual metadata information is saved in the database we
404 * strip some of it since we don't want to save things like thumbnails
405 * which usually accompany Exif data. This value gets saved in the
406 * database along with the actual Exif data, and if the version in the
407 * database doesn't equal the value returned by this function the Exif
408 * data is regenerated.
413 return 1; // We don't need no bloddy constants!
417 * Validates if a tag value is of the type it should be according to the Exif spec
421 * @param $in Mixed: the input value to check
424 function isByte( $in ) {
425 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 255 ) {
426 $this->debug( $in, __FUNCTION__
, true );
429 $this->debug( $in, __FUNCTION__
, false );
434 function isASCII( $in ) {
435 if ( preg_match( "/[^\x0a\x20-\x7e]/", $in ) ) {
436 $this->debug( $in, __FUNCTION__
, 'found a character not in our whitelist' );
440 if ( preg_match( "/^\s*$/", $in ) ) {
441 $this->debug( $in, __FUNCTION__
, 'input consisted solely of whitespace' );
448 function isShort( $in ) {
449 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) {
450 $this->debug( $in, __FUNCTION__
, true );
453 $this->debug( $in, __FUNCTION__
, false );
458 function isLong( $in ) {
459 if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) {
460 $this->debug( $in, __FUNCTION__
, true );
463 $this->debug( $in, __FUNCTION__
, false );
468 function isRational( $in ) {
469 if ( @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 ( 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 ) {
498 if ( preg_match( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
499 return $this->isSlong( $m[0] ) && $this->isSlong( $m[1] );
501 $this->debug( $in, __FUNCTION__
, 'fed a non-fraction value' );
508 * Validates if a tag has a legal value according to the Exif spec
512 * @param $tag String: the tag to check.
513 * @param $val Mixed: the value of the tag.
516 function validate( $tag, $val ) {
517 $debug = "tag is '$tag'";
518 // Fucks up if not typecast
519 switch( (string)$this->mFlatExifTags
[$tag] ) {
520 case (string)MW_EXIF_BYTE
:
521 $this->debug( $val, __FUNCTION__
, $debug );
522 return $this->isByte( $val );
523 case (string)MW_EXIF_ASCII
:
524 $this->debug( $val, __FUNCTION__
, $debug );
525 return $this->isASCII( $val );
526 case (string)MW_EXIF_SHORT
:
527 $this->debug( $val, __FUNCTION__
, $debug );
528 return $this->isShort( $val );
529 case (string)MW_EXIF_LONG
:
530 $this->debug( $val, __FUNCTION__
, $debug );
531 return $this->isLong( $val );
532 case (string)MW_EXIF_RATIONAL
:
533 $this->debug( $val, __FUNCTION__
, $debug );
534 return $this->isRational( $val );
535 case (string)MW_EXIF_UNDEFINED
:
536 $this->debug( $val, __FUNCTION__
, $debug );
537 return $this->isUndefined( $val );
538 case (string)MW_EXIF_SLONG
:
539 $this->debug( $val, __FUNCTION__
, $debug );
540 return $this->isSlong( $val );
541 case (string)MW_EXIF_SRATIONAL
:
542 $this->debug( $val, __FUNCTION__
, $debug );
543 return $this->isSrational( $val );
544 case (string)MW_EXIF_SHORT
.','.MW_EXIF_LONG
:
545 $this->debug( $val, __FUNCTION__
, $debug );
546 return $this->isShort( $val ) ||
$this->isLong( $val );
548 $this->debug( $val, __FUNCTION__
, "The tag '$tag' is unknown" );
554 * Conviniance function for debugging output
559 * @param $fname String:
560 * @param $action Mixed: , default NULL.
562 function debug( $in, $fname, $action = NULL ) {
563 $type = gettype( $in );
564 $class = ucfirst( __CLASS__
);
565 if ( $type === 'array' )
566 $in = print_r( $in, true );
568 if ( $action === true )
569 wfDebugLog( $this->log
, "$class::$fname: accepted: '$in' (type: $type)\n");
570 elseif ( $action === false )
571 wfDebugLog( $this->log
, "$class::$fname: rejected: '$in' (type: $type)\n");
572 elseif ( $action === null )
573 wfDebugLog( $this->log
, "$class::$fname: input was: '$in' (type: $type)\n");
575 wfDebugLog( $this->log
, "$class::$fname: $action (type: $type; content: '$in')\n");
579 * Conviniance function for debugging output
583 * @param $fname String: the name of the function calling this function
584 * @param $io Boolean: Specify whether we're beginning or ending
586 function debugFile( $fname, $io ) {
587 $class = ucfirst( __CLASS__
);
589 wfDebugLog( $this->log
, "$class::$fname: begin processing: '{$this->basename}'\n" );
591 wfDebugLog( $this->log
, "$class::$fname: end processing: '{$this->basename}'\n" );
599 * @subpackage Metadata
603 * The Exif data to format
613 * @param $exif Array: the Exif data to format ( as returned by
614 * Exif::getFilteredData() )
616 function FormatExif( $exif ) {
617 $this->mExif
= $exif;
621 * Numbers given by Exif user agents are often magical, that is they
622 * should be replaced by a detailed explanation depending on their
623 * value which most of the time are plain integers. This function
624 * formats Exif values into human readable form.
628 function getFormattedData() {
631 $tags =& $this->mExif
;
633 $resolutionunit = !isset( $tags['ResolutionUnit'] ) ||
$tags['ResolutionUnit'] == 2 ?
2 : 3;
634 unset( $tags['ResolutionUnit'] );
636 foreach( $tags as $tag => $val ) {
641 $tags[$tag] = $this->msg( $tag, $val );
649 case 'PhotometricInterpretation':
652 $tags[$tag] = $this->msg( $tag, $val );
662 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
663 $tags[$tag] = $this->msg( $tag, $val );
671 case 'PlanarConfiguration':
674 $tags[$tag] = $this->msg( $tag, $val );
682 // TODO: YCbCrSubSampling
683 // TODO: YCbCrPositioning
687 switch( $resolutionunit ) {
689 $tags[$tag] = $this->msg( 'XYResolution', 'i', $this->formatNum( $val ) );
692 $this->msg( 'XYResolution', 'c', $this->formatNum( $val ) );
700 // TODO: YCbCrCoefficients #p27 (see annex E)
701 case 'ExifVersion': case 'FlashpixVersion':
702 $tags[$tag] = "$val"/100;
707 case 1: case 'FFFF.H':
708 $tags[$tag] = $this->msg( $tag, $val );
716 case 'ComponentsConfiguration':
718 case 0: case 1: case 2: case 3: case 4: case 5: case 6:
719 $tags[$tag] = $this->msg( $tag, $val );
728 case 'DateTimeOriginal':
729 case 'DateTimeDigitized':
730 if( preg_match( "/^(\d{4}):(\d\d):(\d\d) (\d\d):(\d\d):(\d\d)$/", $val ) ) {
731 $tags[$tag] = $wgLang->timeanddate( wfTimestamp(TS_MW
, $val) );
735 case 'ExposureProgram':
737 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
738 $tags[$tag] = $this->msg( $tag, $val );
746 case 'SubjectDistance':
747 $tags[$tag] = $this->msg( $tag, '', $this->formatNum( $val ) );
752 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 255:
753 $tags[$tag] = $this->msg( $tag, $val );
763 case 0: case 1: case 2: case 3: case 4: case 9: case 10: case 11:
764 case 12: case 13: case 14: case 15: case 17: case 18: case 19: case 20:
765 case 21: case 22: case 23: case 24: case 255:
766 $tags[$tag] = $this->msg( $tag, $val );
775 case 'FocalPlaneResolutionUnit':
778 $tags[$tag] = $this->msg( $tag, $val );
786 case 'SensingMethod':
788 case 1: case 2: case 3: case 4: case 5: case 7: case 8:
789 $tags[$tag] = $this->msg( $tag, $val );
800 $tags[$tag] = $this->msg( $tag, $val );
811 $tags[$tag] = $this->msg( $tag, $val );
819 case 'CustomRendered':
822 $tags[$tag] = $this->msg( $tag, $val );
832 case 0: case 1: case 2:
833 $tags[$tag] = $this->msg( $tag, $val );
844 $tags[$tag] = $this->msg( $tag, $val );
852 case 'SceneCaptureType':
854 case 0: case 1: case 2: case 3:
855 $tags[$tag] = $this->msg( $tag, $val );
865 case 0: case 1: case 2: case 3: case 4:
866 $tags[$tag] = $this->msg( $tag, $val );
876 case 0: case 1: case 2:
877 $tags[$tag] = $this->msg( $tag, $val );
887 case 0: case 1: case 2:
888 $tags[$tag] = $this->msg( $tag, $val );
898 case 0: case 1: case 2:
899 $tags[$tag] = $this->msg( $tag, $val );
907 case 'SubjectDistanceRange':
909 case 0: case 1: case 2: case 3:
910 $tags[$tag] = $this->msg( $tag, $val );
918 case 'GPSLatitudeRef':
919 case 'GPSDestLatitudeRef':
922 $tags[$tag] = $this->msg( 'GPSLatitude', $val );
930 case 'GPSLongitudeRef':
931 case 'GPSDestLongitudeRef':
934 $tags[$tag] = $this->msg( 'GPSLongitude', $val );
945 $tags[$tag] = $this->msg( $tag, $val );
953 case 'GPSMeasureMode':
956 $tags[$tag] = $this->msg( $tag, $val );
965 case 'GPSDestDistanceRef':
967 case 'K': case 'M': case 'N':
968 $tags[$tag] = $this->msg( 'GPSSpeed', $val );
977 case 'GPSImgDirectionRef':
978 case 'GPSDestBearingRef':
981 $tags[$tag] = $this->msg( 'GPSDirection', $val );
990 $tags[$tag] = $wgLang->date( substr( $val, 0, 4 ) . substr( $val, 5, 2 ) . substr( $val, 8, 2 ) . '000000' );
993 // This is not in the Exif standard, just a special
994 // case for our purposes which enables wikis to wikify
995 // the make, model and software name to link to their articles.
999 $tags[$tag] = $this->msg( $tag, '', $val );
1002 case 'ExposureTime':
1003 // Show the pretty fraction as well as decimal version
1004 $tags[$tag] = wfMsg( 'exif-exposuretime-format',
1005 $this->formatFraction( $val ), $this->formatNum( $val ) );
1009 $tags[$tag] = wfMsg( 'exif-fnumber-format',
1010 $this->formatNum( $val ) );
1014 $tags[$tag] = wfMsg( 'exif-focallength-format',
1015 $this->formatNum( $val ) );
1019 $tags[$tag] = $this->formatNum( $val );
1028 * Conviniance function for getFormattedData()
1032 * @param $tag String: the tag name to pass on
1033 * @param $val String: the value of the tag
1034 * @param $arg String: an argument to pass ($1)
1035 * @return string A wfMsg of "exif-$tag-$val" in lower case
1037 function msg( $tag, $val, $arg = null ) {
1042 return wfMsg( $wgContLang->lc( "exif-$tag-$val" ), $arg );
1046 * Format a number, convert numbers from fractions into floating point
1051 * @param $num Mixed: the value to format
1052 * @return mixed A floating point number or whatever we were fed
1054 function formatNum( $num ) {
1055 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) )
1056 return $m[2] != 0 ?
$m[1] / $m[2] : $num;
1062 * Format a rational number, reducing fractions
1066 * @param $num Mixed: the value to format
1067 * @return mixed A floating point number or whatever we were fed
1069 function formatFraction( $num ) {
1070 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) ) {
1071 $numerator = intval( $m[1] );
1072 $denominator = intval( $m[2] );
1073 $gcd = $this->gcd( $numerator, $denominator );
1075 // 0 shouldn't happen! ;)
1076 return $numerator / $gcd . '/' . $denominator / $gcd;
1079 return $this->formatNum( $num );
1083 * Calculate the greatest common divisor of two integers.
1085 * @param $a Integer: FIXME
1086 * @param $b Integer: FIXME
1090 function gcd( $a, $b ) {
1092 // http://en.wikipedia.org/wiki/Euclidean_algorithm
1093 // Recursive form would be:
1097 return gcd( $b, $a % $b );
1100 $remainder = $a %
$b;
1102 // tail recursion...