6 * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
7 * @copyright Copyright © 2005, Ævar Arnfjörð Bjarmason
8 * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 * http://www.gnu.org/copyleft/gpl.html
25 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
31 * @subpackage Metadata
40 * Exif tag type definition
42 const BYTE
= 1; # An 8-bit (1-byte) unsigned integer.
43 const ASCII
= 2; # An 8-bit byte containing one 7-bit ASCII code. The final byte is terminated with NULL.
44 const SHORT
= 3; # A 16-bit (2-byte) unsigned integer.
45 const LONG
= 4; # A 32-bit (4-byte) unsigned integer.
46 const RATIONAL
= 5; # Two LONGs. The first LONG is the numerator and the second LONG expresses the denominator
47 const UNDEFINED
= 7; # An 8-bit byte that can take any value depending on the field definition
48 const SLONG
= 9; # A 32-bit (4-byte) signed integer (2's complement notation),
49 const SRATIONAL
= 10; # Two SLONGs. The first SLONG is the numerator and the second SLONG is the denominator.
52 * Exif tags grouped by category, the tagname itself is the key and the type
53 * is the value, in the case of more than one possible value type they are
54 * seperated by commas.
59 * A one dimentional array of all Exif tags
64 * The raw Exif data returned by exif_read_data()
69 * A Filtered version of $mRawExifData that has been pruned of invalid
70 * tags and tags that contain content they shouldn't contain according
71 * to the Exif specification
73 var $mFilteredExifData;
76 * Filtered and formatted Exif data, see FormatExif::getFormattedData()
78 var $mFormattedExifData;
88 * The file being processed
93 * The basename of the file being processed
98 * The private log to log to
107 * @param $file String: filename.
109 function Exif( $file ) {
111 * Page numbers here refer to pages in the EXIF 2.2 standard
113 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 specification
115 $this->mExifTags
= array(
116 # TIFF Rev. 6.0 Attribute Information (p22)
118 # Tags relating to image structure
119 'structure' => array(
120 'ImageWidth' => Exif
::SHORT
.','.Exif
::LONG
, # Image width
121 'ImageLength' => Exif
::SHORT
.','.Exif
::LONG
, # Image height
122 'BitsPerSample' => Exif
::SHORT
, # Number of bits per component
123 # "When a primary image is JPEG compressed, this designation is not"
124 # "necessary and is omitted." (p23)
125 'Compression' => Exif
::SHORT
, # Compression scheme #p23
126 'PhotometricInterpretation' => Exif
::SHORT
, # Pixel composition #p23
127 'Orientation' => Exif
::SHORT
, # Orientation of image #p24
128 'SamplesPerPixel' => Exif
::SHORT
, # Number of components
129 'PlanarConfiguration' => Exif
::SHORT
, # Image data arrangement #p24
130 'YCbCrSubSampling' => Exif
::SHORT
, # Subsampling ratio of Y to C #p24
131 'YCbCrPositioning' => Exif
::SHORT
, # Y and C positioning #p24-25
132 'XResolution' => Exif
::RATIONAL
, # Image resolution in width direction
133 'YResolution' => Exif
::RATIONAL
, # Image resolution in height direction
134 'ResolutionUnit' => Exif
::SHORT
, # Unit of X and Y resolution #(p26)
137 # Tags relating to recording offset
139 'StripOffsets' => Exif
::SHORT
.','.Exif
::LONG
, # Image data location
140 'RowsPerStrip' => Exif
::SHORT
.','.Exif
::LONG
, # Number of rows per strip
141 'StripByteCounts' => Exif
::SHORT
.','.Exif
::LONG
, # Bytes per compressed strip
142 'JPEGInterchangeFormat' => Exif
::SHORT
.','.Exif
::LONG
, # Offset to JPEG SOI
143 'JPEGInterchangeFormatLength' => Exif
::SHORT
.','.Exif
::LONG
, # Bytes of JPEG data
146 # Tags relating to image data characteristics
147 'characteristics' => array(
148 'TransferFunction' => Exif
::SHORT
, # Transfer function
149 'WhitePoint' => Exif
::RATIONAL
, # White point chromaticity
150 'PrimaryChromaticities' => Exif
::RATIONAL
, # Chromaticities of primarities
151 'YCbCrCoefficients' => Exif
::RATIONAL
, # Color space transformation matrix coefficients #p27
152 'ReferenceBlackWhite' => Exif
::RATIONAL
# Pair of black and white reference values
157 'DateTime' => Exif
::ASCII
, # File change date and time
158 'ImageDescription' => Exif
::ASCII
, # Image title
159 'Make' => Exif
::ASCII
, # Image input equipment manufacturer
160 'Model' => Exif
::ASCII
, # Image input equipment model
161 'Software' => Exif
::ASCII
, # Software used
162 'Artist' => Exif
::ASCII
, # Person who created the image
163 'Copyright' => Exif
::ASCII
, # Copyright holder
167 # Exif IFD Attribute Information (p30-31)
169 # Tags relating to version
171 # TODO: NOTE: Nonexistence of this field is taken to mean nonconformance
172 # to the EXIF 2.1 AND 2.2 standards
173 'ExifVersion' => Exif
::UNDEFINED
, # Exif version
174 'FlashpixVersion' => Exif
::UNDEFINED
, # Supported Flashpix version #p32
177 # Tags relating to Image Data Characteristics
178 'characteristics' => array(
179 'ColorSpace' => Exif
::SHORT
, # Color space information #p32
182 # Tags relating to image configuration
183 'configuration' => array(
184 'ComponentsConfiguration' => Exif
::UNDEFINED
, # Meaning of each component #p33
185 'CompressedBitsPerPixel' => Exif
::RATIONAL
, # Image compression mode
186 'PixelYDimension' => Exif
::SHORT
.','.Exif
::LONG
, # Valid image width
187 'PixelXDimension' => Exif
::SHORT
.','.Exif
::LONG
, # Valind image height
190 # Tags relating to related user information
192 'MakerNote' => Exif
::UNDEFINED
, # Manufacturer notes
193 'UserComment' => Exif
::UNDEFINED
, # User comments #p34
196 # Tags relating to related file information
198 'RelatedSoundFile' => Exif
::ASCII
, # Related audio file
201 # Tags relating to date and time
202 'dateandtime' => array(
203 'DateTimeOriginal' => Exif
::ASCII
, # Date and time of original data generation #p36
204 'DateTimeDigitized' => Exif
::ASCII
, # Date and time of original data generation
205 'SubSecTime' => Exif
::ASCII
, # DateTime subseconds
206 'SubSecTimeOriginal' => Exif
::ASCII
, # DateTimeOriginal subseconds
207 'SubSecTimeDigitized' => Exif
::ASCII
, # DateTimeDigitized subseconds
210 # Tags relating to picture-taking conditions (p31)
211 'conditions' => array(
212 'ExposureTime' => Exif
::RATIONAL
, # Exposure time
213 'FNumber' => Exif
::RATIONAL
, # F Number
214 'ExposureProgram' => Exif
::SHORT
, # Exposure Program #p38
215 'SpectralSensitivity' => Exif
::ASCII
, # Spectral sensitivity
216 'ISOSpeedRatings' => Exif
::SHORT
, # ISO speed rating
217 'OECF' => Exif
::UNDEFINED
, # Optoelectronic conversion factor
218 'ShutterSpeedValue' => Exif
::SRATIONAL
, # Shutter speed
219 'ApertureValue' => Exif
::RATIONAL
, # Aperture
220 'BrightnessValue' => Exif
::SRATIONAL
, # Brightness
221 'ExposureBiasValue' => Exif
::SRATIONAL
, # Exposure bias
222 'MaxApertureValue' => Exif
::RATIONAL
, # Maximum land aperture
223 'SubjectDistance' => Exif
::RATIONAL
, # Subject distance
224 'MeteringMode' => Exif
::SHORT
, # Metering mode #p40
225 'LightSource' => Exif
::SHORT
, # Light source #p40-41
226 'Flash' => Exif
::SHORT
, # Flash #p41-42
227 'FocalLength' => Exif
::RATIONAL
, # Lens focal length
228 'SubjectArea' => Exif
::SHORT
, # Subject area
229 'FlashEnergy' => Exif
::RATIONAL
, # Flash energy
230 'SpatialFrequencyResponse' => Exif
::UNDEFINED
, # Spatial frequency response
231 'FocalPlaneXResolution' => Exif
::RATIONAL
, # Focal plane X resolution
232 'FocalPlaneYResolution' => Exif
::RATIONAL
, # Focal plane Y resolution
233 'FocalPlaneResolutionUnit' => Exif
::SHORT
, # Focal plane resolution unit #p46
234 'SubjectLocation' => Exif
::SHORT
, # Subject location
235 'ExposureIndex' => Exif
::RATIONAL
, # Exposure index
236 'SensingMethod' => Exif
::SHORT
, # Sensing method #p46
237 'FileSource' => Exif
::UNDEFINED
, # File source #p47
238 'SceneType' => Exif
::UNDEFINED
, # Scene type #p47
239 'CFAPattern' => Exif
::UNDEFINED
, # CFA pattern
240 'CustomRendered' => Exif
::SHORT
, # Custom image processing #p48
241 'ExposureMode' => Exif
::SHORT
, # Exposure mode #p48
242 'WhiteBalance' => Exif
::SHORT
, # White Balance #p49
243 'DigitalZoomRatio' => Exif
::RATIONAL
, # Digital zoom ration
244 'FocalLengthIn35mmFilm' => Exif
::SHORT
, # Focal length in 35 mm film
245 'SceneCaptureType' => Exif
::SHORT
, # Scene capture type #p49
246 'GainControl' => Exif
::RATIONAL
, # Scene control #p49-50
247 'Contrast' => Exif
::SHORT
, # Contrast #p50
248 'Saturation' => Exif
::SHORT
, # Saturation #p50
249 'Sharpness' => Exif
::SHORT
, # Sharpness #p50
250 'DeviceSettingDescription' => Exif
::UNDEFINED
, # Desice settings description
251 'SubjectDistanceRange' => Exif
::SHORT
, # Subject distance range #p51
255 'ImageUniqueID' => Exif
::ASCII
, # Unique image ID
259 # GPS Attribute Information (p52)
261 'GPSVersionID' => Exif
::BYTE
, # GPS tag version
262 'GPSLatitudeRef' => Exif
::ASCII
, # North or South Latitude #p52-53
263 'GPSLatitude' => Exif
::RATIONAL
, # Latitude
264 'GPSLongitudeRef' => Exif
::ASCII
, # East or West Longitude #p53
265 'GPSLongitude' => Exif
::RATIONAL
, # Longitude
266 'GPSAltitudeRef' => Exif
::BYTE
, # Altitude reference
267 'GPSAltitude' => Exif
::RATIONAL
, # Altitude
268 'GPSTimeStamp' => Exif
::RATIONAL
, # GPS time (atomic clock)
269 'GPSSatellites' => Exif
::ASCII
, # Satellites used for measurement
270 'GPSStatus' => Exif
::ASCII
, # Receiver status #p54
271 'GPSMeasureMode' => Exif
::ASCII
, # Measurement mode #p54-55
272 'GPSDOP' => Exif
::RATIONAL
, # Measurement precision
273 'GPSSpeedRef' => Exif
::ASCII
, # Speed unit #p55
274 'GPSSpeed' => Exif
::RATIONAL
, # Speed of GPS receiver
275 'GPSTrackRef' => Exif
::ASCII
, # Reference for direction of movement #p55
276 'GPSTrack' => Exif
::RATIONAL
, # Direction of movement
277 'GPSImgDirectionRef' => Exif
::ASCII
, # Reference for direction of image #p56
278 'GPSImgDirection' => Exif
::RATIONAL
, # Direction of image
279 'GPSMapDatum' => Exif
::ASCII
, # Geodetic survey data used
280 'GPSDestLatitudeRef' => Exif
::ASCII
, # Reference for latitude of destination #p56
281 'GPSDestLatitude' => Exif
::RATIONAL
, # Latitude destination
282 'GPSDestLongitudeRef' => Exif
::ASCII
, # Reference for longitude of destination #p57
283 'GPSDestLongitude' => Exif
::RATIONAL
, # Longitude of destination
284 'GPSDestBearingRef' => Exif
::ASCII
, # Reference for bearing of destination #p57
285 'GPSDestBearing' => Exif
::RATIONAL
, # Bearing of destination
286 'GPSDestDistanceRef' => Exif
::ASCII
, # Reference for distance to destination #p57-58
287 'GPSDestDistance' => Exif
::RATIONAL
, # Distance to destination
288 'GPSProcessingMethod' => Exif
::UNDEFINED
, # Name of GPS processing method
289 'GPSAreaInformation' => Exif
::UNDEFINED
, # Name of GPS area
290 'GPSDateStamp' => Exif
::ASCII
, # GPS date
291 'GPSDifferential' => Exif
::SHORT
, # GPS differential correction
296 $this->basename
= wfBaseName( $this->file
);
298 $this->makeFlatExifTags();
300 $this->debugFile( $this->basename
, __FUNCTION__
, true );
301 wfSuppressWarnings();
302 $data = exif_read_data( $this->file
);
305 * exif_read_data() will return false on invalid input, such as
306 * when somebody uploads a file called something.jpeg
307 * containing random gibberish.
309 $this->mRawExifData
= $data ?
$data : array();
311 $this->makeFilteredData();
312 $this->makeFormattedData();
314 $this->debugFile( __FUNCTION__
, false );
321 * Generate a flat list of the exif tags
323 function makeFlatExifTags() {
324 $this->extractTags( $this->mExifTags
);
328 * A recursing extractor function used by makeFlatExifTags()
330 * Note: This used to use an array_walk function, but it made PHP5
331 * segfault, see `cvs diff -u -r 1.4 -r 1.5 Exif.php`
333 function extractTags( &$tagset ) {
334 foreach( $tagset as $key => $val ) {
335 if( is_array( $val ) ) {
336 $this->extractTags( $val );
338 $this->mFlatExifTags
[$key] = $val;
344 * Make $this->mFilteredExifData
346 function makeFilteredData() {
347 $this->mFilteredExifData
= $this->mRawExifData
;
349 foreach( $this->mFilteredExifData
as $k => $v ) {
350 if ( !in_array( $k, array_keys( $this->mFlatExifTags
) ) ) {
351 $this->debug( $v, __FUNCTION__
, "'$k' is not a valid Exif tag" );
352 unset( $this->mFilteredExifData
[$k] );
356 foreach( $this->mFilteredExifData
as $k => $v ) {
357 if ( !$this->validate($k, $v) ) {
358 $this->debug( $v, __FUNCTION__
, "'$k' contained invalid data" );
359 unset( $this->mFilteredExifData
[$k] );
367 function makeFormattedData( ) {
368 $format = new FormatExif( $this->getFilteredData() );
369 $this->mFormattedExifData
= $format->getFormattedData();
377 * Get $this->mRawExifData
380 return $this->mRawExifData
;
384 * Get $this->mFilteredExifData
386 function getFilteredData() {
387 return $this->mFilteredExifData
;
391 * Get $this->mFormattedExifData
393 function getFormattedData() {
394 return $this->mFormattedExifData
;
399 * The version of the output format
401 * Before the actual metadata information is saved in the database we
402 * strip some of it since we don't want to save things like thumbnails
403 * which usually accompany Exif data. This value gets saved in the
404 * database along with the actual Exif data, and if the version in the
405 * database doesn't equal the value returned by this function the Exif
406 * data is regenerated.
411 return 1; // We don't need no bloddy constants!
415 * Validates if a tag value is of the type it should be according to the Exif spec
419 * @param $in Mixed: the input value to check
422 function isByte( $in ) {
423 if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 255 ) {
424 $this->debug( $in, __FUNCTION__
, true );
427 $this->debug( $in, __FUNCTION__
, false );
432 function isASCII( $in ) {
433 if ( is_array( $in ) ) {
437 if ( preg_match( "/[^\x0a\x20-\x7e]/", $in ) ) {
438 $this->debug( $in, __FUNCTION__
, 'found a character not in our whitelist' );
442 if ( preg_match( "/^\s*$/", $in ) ) {
443 $this->debug( $in, __FUNCTION__
, 'input consisted solely of whitespace' );
450 function isShort( $in ) {
451 if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) {
452 $this->debug( $in, __FUNCTION__
, true );
455 $this->debug( $in, __FUNCTION__
, false );
460 function isLong( $in ) {
461 if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) {
462 $this->debug( $in, __FUNCTION__
, true );
465 $this->debug( $in, __FUNCTION__
, false );
470 function isRational( $in ) {
471 if ( !is_array( $in ) && @preg_match
( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
472 return $this->isLong( $m[1] ) && $this->isLong( $m[2] );
474 $this->debug( $in, __FUNCTION__
, 'fed a non-fraction value' );
479 function isUndefined( $in ) {
480 if ( !is_array( $in ) && preg_match( "/^\d{4}$/", $in ) ) { // Allow ExifVersion and FlashpixVersion
481 $this->debug( $in, __FUNCTION__
, true );
484 $this->debug( $in, __FUNCTION__
, false );
489 function isSlong( $in ) {
490 if ( $this->isLong( abs( $in ) ) ) {
491 $this->debug( $in, __FUNCTION__
, true );
494 $this->debug( $in, __FUNCTION__
, false );
499 function isSrational( $in ) {
500 if ( !is_array( $in ) && preg_match( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
501 return $this->isSlong( $m[0] ) && $this->isSlong( $m[1] );
503 $this->debug( $in, __FUNCTION__
, 'fed a non-fraction value' );
510 * Validates if a tag has a legal value according to the Exif spec
514 * @param $tag String: the tag to check.
515 * @param $val Mixed: the value of the tag.
518 function validate( $tag, $val ) {
519 $debug = "tag is '$tag'";
520 // Does not work if not typecast
521 switch( (string)$this->mFlatExifTags
[$tag] ) {
522 case (string)Exif
::BYTE
:
523 $this->debug( $val, __FUNCTION__
, $debug );
524 return $this->isByte( $val );
525 case (string)Exif
::ASCII
:
526 $this->debug( $val, __FUNCTION__
, $debug );
527 return $this->isASCII( $val );
528 case (string)Exif
::SHORT
:
529 $this->debug( $val, __FUNCTION__
, $debug );
530 return $this->isShort( $val );
531 case (string)Exif
::LONG
:
532 $this->debug( $val, __FUNCTION__
, $debug );
533 return $this->isLong( $val );
534 case (string)Exif
::RATIONAL
:
535 $this->debug( $val, __FUNCTION__
, $debug );
536 return $this->isRational( $val );
537 case (string)Exif
::UNDEFINED
:
538 $this->debug( $val, __FUNCTION__
, $debug );
539 return $this->isUndefined( $val );
540 case (string)Exif
::SLONG
:
541 $this->debug( $val, __FUNCTION__
, $debug );
542 return $this->isSlong( $val );
543 case (string)Exif
::SRATIONAL
:
544 $this->debug( $val, __FUNCTION__
, $debug );
545 return $this->isSrational( $val );
546 case (string)Exif
::SHORT
.','.Exif
::LONG
:
547 $this->debug( $val, __FUNCTION__
, $debug );
548 return $this->isShort( $val ) ||
$this->isLong( $val );
550 $this->debug( $val, __FUNCTION__
, "The tag '$tag' is unknown" );
556 * Convenience function for debugging output
561 * @param $fname String:
562 * @param $action Mixed: , default NULL.
564 function debug( $in, $fname, $action = NULL ) {
565 $type = gettype( $in );
566 $class = ucfirst( __CLASS__
);
567 if ( $type === 'array' )
568 $in = print_r( $in, true );
570 if ( $action === true )
571 wfDebugLog( $this->log
, "$class::$fname: accepted: '$in' (type: $type)\n");
572 elseif ( $action === false )
573 wfDebugLog( $this->log
, "$class::$fname: rejected: '$in' (type: $type)\n");
574 elseif ( $action === null )
575 wfDebugLog( $this->log
, "$class::$fname: input was: '$in' (type: $type)\n");
577 wfDebugLog( $this->log
, "$class::$fname: $action (type: $type; content: '$in')\n");
581 * Convenience function for debugging output
585 * @param $fname String: the name of the function calling this function
586 * @param $io Boolean: Specify whether we're beginning or ending
588 function debugFile( $fname, $io ) {
589 $class = ucfirst( __CLASS__
);
591 wfDebugLog( $this->log
, "$class::$fname: begin processing: '{$this->basename}'\n" );
593 wfDebugLog( $this->log
, "$class::$fname: end processing: '{$this->basename}'\n" );
601 * @subpackage Metadata
605 * The Exif data to format
615 * @param $exif Array: the Exif data to format ( as returned by
616 * Exif::getFilteredData() )
618 function FormatExif( $exif ) {
619 $this->mExif
= $exif;
623 * Numbers given by Exif user agents are often magical, that is they
624 * should be replaced by a detailed explanation depending on their
625 * value which most of the time are plain integers. This function
626 * formats Exif values into human readable form.
630 function getFormattedData() {
633 $tags =& $this->mExif
;
635 $resolutionunit = !isset( $tags['ResolutionUnit'] ) ||
$tags['ResolutionUnit'] == 2 ?
2 : 3;
636 unset( $tags['ResolutionUnit'] );
638 foreach( $tags as $tag => $val ) {
643 $tags[$tag] = $this->msg( $tag, $val );
651 case 'PhotometricInterpretation':
654 $tags[$tag] = $this->msg( $tag, $val );
664 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
665 $tags[$tag] = $this->msg( $tag, $val );
673 case 'PlanarConfiguration':
676 $tags[$tag] = $this->msg( $tag, $val );
684 // TODO: YCbCrSubSampling
685 // TODO: YCbCrPositioning
689 switch( $resolutionunit ) {
691 $tags[$tag] = $this->msg( 'XYResolution', 'i', $this->formatNum( $val ) );
694 $this->msg( 'XYResolution', 'c', $this->formatNum( $val ) );
702 // TODO: YCbCrCoefficients #p27 (see annex E)
703 case 'ExifVersion': case 'FlashpixVersion':
704 $tags[$tag] = "$val"/100;
709 case 1: case 'FFFF.H':
710 $tags[$tag] = $this->msg( $tag, $val );
718 case 'ComponentsConfiguration':
720 case 0: case 1: case 2: case 3: case 4: case 5: case 6:
721 $tags[$tag] = $this->msg( $tag, $val );
730 case 'DateTimeOriginal':
731 case 'DateTimeDigitized':
732 if( preg_match( "/^(\d{4}):(\d\d):(\d\d) (\d\d):(\d\d):(\d\d)$/", $val ) ) {
733 $tags[$tag] = $wgLang->timeanddate( wfTimestamp(TS_MW
, $val) );
737 case 'ExposureProgram':
739 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
740 $tags[$tag] = $this->msg( $tag, $val );
748 case 'SubjectDistance':
749 $tags[$tag] = $this->msg( $tag, '', $this->formatNum( $val ) );
754 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 255:
755 $tags[$tag] = $this->msg( $tag, $val );
765 case 0: case 1: case 2: case 3: case 4: case 9: case 10: case 11:
766 case 12: case 13: case 14: case 15: case 17: case 18: case 19: case 20:
767 case 21: case 22: case 23: case 24: case 255:
768 $tags[$tag] = $this->msg( $tag, $val );
777 case 'FocalPlaneResolutionUnit':
780 $tags[$tag] = $this->msg( $tag, $val );
788 case 'SensingMethod':
790 case 1: case 2: case 3: case 4: case 5: case 7: case 8:
791 $tags[$tag] = $this->msg( $tag, $val );
802 $tags[$tag] = $this->msg( $tag, $val );
813 $tags[$tag] = $this->msg( $tag, $val );
821 case 'CustomRendered':
824 $tags[$tag] = $this->msg( $tag, $val );
834 case 0: case 1: case 2:
835 $tags[$tag] = $this->msg( $tag, $val );
846 $tags[$tag] = $this->msg( $tag, $val );
854 case 'SceneCaptureType':
856 case 0: case 1: case 2: case 3:
857 $tags[$tag] = $this->msg( $tag, $val );
867 case 0: case 1: case 2: case 3: case 4:
868 $tags[$tag] = $this->msg( $tag, $val );
878 case 0: case 1: case 2:
879 $tags[$tag] = $this->msg( $tag, $val );
889 case 0: case 1: case 2:
890 $tags[$tag] = $this->msg( $tag, $val );
900 case 0: case 1: case 2:
901 $tags[$tag] = $this->msg( $tag, $val );
909 case 'SubjectDistanceRange':
911 case 0: case 1: case 2: case 3:
912 $tags[$tag] = $this->msg( $tag, $val );
920 case 'GPSLatitudeRef':
921 case 'GPSDestLatitudeRef':
924 $tags[$tag] = $this->msg( 'GPSLatitude', $val );
932 case 'GPSLongitudeRef':
933 case 'GPSDestLongitudeRef':
936 $tags[$tag] = $this->msg( 'GPSLongitude', $val );
947 $tags[$tag] = $this->msg( $tag, $val );
955 case 'GPSMeasureMode':
958 $tags[$tag] = $this->msg( $tag, $val );
967 case 'GPSDestDistanceRef':
969 case 'K': case 'M': case 'N':
970 $tags[$tag] = $this->msg( 'GPSSpeed', $val );
979 case 'GPSImgDirectionRef':
980 case 'GPSDestBearingRef':
983 $tags[$tag] = $this->msg( 'GPSDirection', $val );
992 $tags[$tag] = $wgLang->date( substr( $val, 0, 4 ) . substr( $val, 5, 2 ) . substr( $val, 8, 2 ) . '000000' );
995 // This is not in the Exif standard, just a special
996 // case for our purposes which enables wikis to wikify
997 // the make, model and software name to link to their articles.
1001 $tags[$tag] = $this->msg( $tag, '', $val );
1004 case 'ExposureTime':
1005 // Show the pretty fraction as well as decimal version
1006 $tags[$tag] = wfMsg( 'exif-exposuretime-format',
1007 $this->formatFraction( $val ), $this->formatNum( $val ) );
1011 $tags[$tag] = wfMsg( 'exif-fnumber-format',
1012 $this->formatNum( $val ) );
1016 $tags[$tag] = wfMsg( 'exif-focallength-format',
1017 $this->formatNum( $val ) );
1021 $tags[$tag] = $this->formatNum( $val );
1030 * Convenience function for getFormattedData()
1034 * @param $tag String: the tag name to pass on
1035 * @param $val String: the value of the tag
1036 * @param $arg String: an argument to pass ($1)
1037 * @return string A wfMsg of "exif-$tag-$val" in lower case
1039 function msg( $tag, $val, $arg = null ) {
1044 return wfMsg( $wgContLang->lc( "exif-$tag-$val" ), $arg );
1048 * Format a number, convert numbers from fractions into floating point
1053 * @param $num Mixed: the value to format
1054 * @return mixed A floating point number or whatever we were fed
1056 function formatNum( $num ) {
1057 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) )
1058 return $m[2] != 0 ?
$m[1] / $m[2] : $num;
1064 * Format a rational number, reducing fractions
1068 * @param $num Mixed: the value to format
1069 * @return mixed A floating point number or whatever we were fed
1071 function formatFraction( $num ) {
1072 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) ) {
1073 $numerator = intval( $m[1] );
1074 $denominator = intval( $m[2] );
1075 $gcd = $this->gcd( $numerator, $denominator );
1077 // 0 shouldn't happen! ;)
1078 return $numerator / $gcd . '/' . $denominator / $gcd;
1081 return $this->formatNum( $num );
1085 * Calculate the greatest common divisor of two integers.
1087 * @param $a Integer: FIXME
1088 * @param $b Integer: FIXME
1092 function gcd( $a, $b ) {
1094 // http://en.wikipedia.org/wiki/Euclidean_algorithm
1095 // Recursive form would be:
1099 return gcd( $b, $a % $b );
1102 $remainder = $a %
$b;
1104 // tail recursion...
1113 * MW 1.6 compatibility
1115 define( 'MW_EXIF_BYTE', Exif
::BYTE
);
1116 define( 'MW_EXIF_ASCII', Exif
::ASCII
);
1117 define( 'MW_EXIF_SHORT', Exif
::SHORT
);
1118 define( 'MW_EXIF_LONG', Exif
::LONG
);
1119 define( 'MW_EXIF_RATIONAL', Exif
::RATIONAL
);
1120 define( 'MW_EXIF_UNDEFINED', Exif
::UNDEFINED
);
1121 define( 'MW_EXIF_SLONG', Exif
::SLONG
);
1122 define( 'MW_EXIF_SRATIONAL', Exif
::SRATIONAL
);