00001 <?php
00030 class Exif {
00031
00032 const BYTE = 1;
00033 const ASCII = 2;
00034 const SHORT = 3;
00035 const LONG = 4;
00036 const RATIONAL = 5;
00037 const UNDEFINED = 7;
00038 const SLONG = 9;
00039 const SRATIONAL = 10;
00040
00042
00043
00044
00045
00051 var $mExifTags;
00052
00056 var $mFlatExifTags;
00057
00061 var $mRawExifData;
00062
00068 var $mFilteredExifData;
00069
00073 var $mFormattedExifData;
00074
00076
00078
00079
00080
00081
00085 var $file;
00086
00090 var $basename;
00091
00095 var $log = false;
00096
00098
00104 function __construct( $file ) {
00110 $this->mExifTags = array(
00111 # TIFF Rev. 6.0 Attribute Information (p22)
00112 'tiff' => array(
00113 # Tags relating to image structure
00114 'structure' => array(
00115 'ImageWidth' => Exif::SHORT.','.Exif::LONG, # Image width
00116 'ImageLength' => Exif::SHORT.','.Exif::LONG, # Image height
00117 'BitsPerSample' => Exif::SHORT, # Number of bits per component
00118 # "When a primary image is JPEG compressed, this designation is not"
00119 # "necessary and is omitted." (p23)
00120 'Compression' => Exif::SHORT, # Compression scheme #p23
00121 'PhotometricInterpretation' => Exif::SHORT, # Pixel composition #p23
00122 'Orientation' => Exif::SHORT, # Orientation of image #p24
00123 'SamplesPerPixel' => Exif::SHORT, # Number of components
00124 'PlanarConfiguration' => Exif::SHORT, # Image data arrangement #p24
00125 'YCbCrSubSampling' => Exif::SHORT, # Subsampling ratio of Y to C #p24
00126 'YCbCrPositioning' => Exif::SHORT, # Y and C positioning #p24-25
00127 'XResolution' => Exif::RATIONAL, # Image resolution in width direction
00128 'YResolution' => Exif::RATIONAL, # Image resolution in height direction
00129 'ResolutionUnit' => Exif::SHORT, # Unit of X and Y resolution #(p26)
00130 ),
00131
00132 # Tags relating to recording offset
00133 'offset' => array(
00134 'StripOffsets' => Exif::SHORT.','.Exif::LONG, # Image data location
00135 'RowsPerStrip' => Exif::SHORT.','.Exif::LONG, # Number of rows per strip
00136 'StripByteCounts' => Exif::SHORT.','.Exif::LONG, # Bytes per compressed strip
00137 'JPEGInterchangeFormat' => Exif::SHORT.','.Exif::LONG, # Offset to JPEG SOI
00138 'JPEGInterchangeFormatLength' => Exif::SHORT.','.Exif::LONG, # Bytes of JPEG data
00139 ),
00140
00141 # Tags relating to image data characteristics
00142 'characteristics' => array(
00143 'TransferFunction' => Exif::SHORT, # Transfer function
00144 'WhitePoint' => Exif::RATIONAL, # White point chromaticity
00145 'PrimaryChromaticities' => Exif::RATIONAL, # Chromaticities of primarities
00146 'YCbCrCoefficients' => Exif::RATIONAL, # Color space transformation matrix coefficients #p27
00147 'ReferenceBlackWhite' => Exif::RATIONAL # Pair of black and white reference values
00148 ),
00149
00150 # Other tags
00151 'other' => array(
00152 'DateTime' => Exif::ASCII, # File change date and time
00153 'ImageDescription' => Exif::ASCII, # Image title
00154 'Make' => Exif::ASCII, # Image input equipment manufacturer
00155 'Model' => Exif::ASCII, # Image input equipment model
00156 'Software' => Exif::ASCII, # Software used
00157 'Artist' => Exif::ASCII, # Person who created the image
00158 'Copyright' => Exif::ASCII, # Copyright holder
00159 ),
00160 ),
00161
00162 # Exif IFD Attribute Information (p30-31)
00163 'exif' => array(
00164 # Tags relating to version
00165 'version' => array(
00166 # TODO: NOTE: Nonexistence of this field is taken to mean nonconformance
00167 # to the EXIF 2.1 AND 2.2 standards
00168 'ExifVersion' => Exif::UNDEFINED, # Exif version
00169 'FlashpixVersion' => Exif::UNDEFINED, # Supported Flashpix version #p32
00170 ),
00171
00172 # Tags relating to Image Data Characteristics
00173 'characteristics' => array(
00174 'ColorSpace' => Exif::SHORT, # Color space information #p32
00175 ),
00176
00177 # Tags relating to image configuration
00178 'configuration' => array(
00179 'ComponentsConfiguration' => Exif::UNDEFINED, # Meaning of each component #p33
00180 'CompressedBitsPerPixel' => Exif::RATIONAL, # Image compression mode
00181 'PixelYDimension' => Exif::SHORT.','.Exif::LONG, # Valid image width
00182 'PixelXDimension' => Exif::SHORT.','.Exif::LONG, # Valind image height
00183 ),
00184
00185 # Tags relating to related user information
00186 'user' => array(
00187 'MakerNote' => Exif::UNDEFINED, # Manufacturer notes
00188 'UserComment' => Exif::UNDEFINED, # User comments #p34
00189 ),
00190
00191 # Tags relating to related file information
00192 'related' => array(
00193 'RelatedSoundFile' => Exif::ASCII, # Related audio file
00194 ),
00195
00196 # Tags relating to date and time
00197 'dateandtime' => array(
00198 'DateTimeOriginal' => Exif::ASCII, # Date and time of original data generation #p36
00199 'DateTimeDigitized' => Exif::ASCII, # Date and time of original data generation
00200 'SubSecTime' => Exif::ASCII, # DateTime subseconds
00201 'SubSecTimeOriginal' => Exif::ASCII, # DateTimeOriginal subseconds
00202 'SubSecTimeDigitized' => Exif::ASCII, # DateTimeDigitized subseconds
00203 ),
00204
00205 # Tags relating to picture-taking conditions (p31)
00206 'conditions' => array(
00207 'ExposureTime' => Exif::RATIONAL, # Exposure time
00208 'FNumber' => Exif::RATIONAL, # F Number
00209 'ExposureProgram' => Exif::SHORT, # Exposure Program #p38
00210 'SpectralSensitivity' => Exif::ASCII, # Spectral sensitivity
00211 'ISOSpeedRatings' => Exif::SHORT, # ISO speed rating
00212 'OECF' => Exif::UNDEFINED, # Optoelectronic conversion factor
00213 'ShutterSpeedValue' => Exif::SRATIONAL, # Shutter speed
00214 'ApertureValue' => Exif::RATIONAL, # Aperture
00215 'BrightnessValue' => Exif::SRATIONAL, # Brightness
00216 'ExposureBiasValue' => Exif::SRATIONAL, # Exposure bias
00217 'MaxApertureValue' => Exif::RATIONAL, # Maximum land aperture
00218 'SubjectDistance' => Exif::RATIONAL, # Subject distance
00219 'MeteringMode' => Exif::SHORT, # Metering mode #p40
00220 'LightSource' => Exif::SHORT, # Light source #p40-41
00221 'Flash' => Exif::SHORT, # Flash #p41-42
00222 'FocalLength' => Exif::RATIONAL, # Lens focal length
00223 'SubjectArea' => Exif::SHORT, # Subject area
00224 'FlashEnergy' => Exif::RATIONAL, # Flash energy
00225 'SpatialFrequencyResponse' => Exif::UNDEFINED, # Spatial frequency response
00226 'FocalPlaneXResolution' => Exif::RATIONAL, # Focal plane X resolution
00227 'FocalPlaneYResolution' => Exif::RATIONAL, # Focal plane Y resolution
00228 'FocalPlaneResolutionUnit' => Exif::SHORT, # Focal plane resolution unit #p46
00229 'SubjectLocation' => Exif::SHORT, # Subject location
00230 'ExposureIndex' => Exif::RATIONAL, # Exposure index
00231 'SensingMethod' => Exif::SHORT, # Sensing method #p46
00232 'FileSource' => Exif::UNDEFINED, # File source #p47
00233 'SceneType' => Exif::UNDEFINED, # Scene type #p47
00234 'CFAPattern' => Exif::UNDEFINED, # CFA pattern
00235 'CustomRendered' => Exif::SHORT, # Custom image processing #p48
00236 'ExposureMode' => Exif::SHORT, # Exposure mode #p48
00237 'WhiteBalance' => Exif::SHORT, # White Balance #p49
00238 'DigitalZoomRatio' => Exif::RATIONAL, # Digital zoom ration
00239 'FocalLengthIn35mmFilm' => Exif::SHORT, # Focal length in 35 mm film
00240 'SceneCaptureType' => Exif::SHORT, # Scene capture type #p49
00241 'GainControl' => Exif::RATIONAL, # Scene control #p49-50
00242 'Contrast' => Exif::SHORT, # Contrast #p50
00243 'Saturation' => Exif::SHORT, # Saturation #p50
00244 'Sharpness' => Exif::SHORT, # Sharpness #p50
00245 'DeviceSettingDescription' => Exif::UNDEFINED, # Desice settings description
00246 'SubjectDistanceRange' => Exif::SHORT, # Subject distance range #p51
00247 ),
00248
00249 'other' => array(
00250 'ImageUniqueID' => Exif::ASCII, # Unique image ID
00251 ),
00252 ),
00253
00254 # GPS Attribute Information (p52)
00255 'gps' => array(
00256 'GPSVersionID' => Exif::BYTE, # GPS tag version
00257 'GPSLatitudeRef' => Exif::ASCII, # North or South Latitude #p52-53
00258 'GPSLatitude' => Exif::RATIONAL, # Latitude
00259 'GPSLongitudeRef' => Exif::ASCII, # East or West Longitude #p53
00260 'GPSLongitude' => Exif::RATIONAL, # Longitude
00261 'GPSAltitudeRef' => Exif::BYTE, # Altitude reference
00262 'GPSAltitude' => Exif::RATIONAL, # Altitude
00263 'GPSTimeStamp' => Exif::RATIONAL, # GPS time (atomic clock)
00264 'GPSSatellites' => Exif::ASCII, # Satellites used for measurement
00265 'GPSStatus' => Exif::ASCII, # Receiver status #p54
00266 'GPSMeasureMode' => Exif::ASCII, # Measurement mode #p54-55
00267 'GPSDOP' => Exif::RATIONAL, # Measurement precision
00268 'GPSSpeedRef' => Exif::ASCII, # Speed unit #p55
00269 'GPSSpeed' => Exif::RATIONAL, # Speed of GPS receiver
00270 'GPSTrackRef' => Exif::ASCII, # Reference for direction of movement #p55
00271 'GPSTrack' => Exif::RATIONAL, # Direction of movement
00272 'GPSImgDirectionRef' => Exif::ASCII, # Reference for direction of image #p56
00273 'GPSImgDirection' => Exif::RATIONAL, # Direction of image
00274 'GPSMapDatum' => Exif::ASCII, # Geodetic survey data used
00275 'GPSDestLatitudeRef' => Exif::ASCII, # Reference for latitude of destination #p56
00276 'GPSDestLatitude' => Exif::RATIONAL, # Latitude destination
00277 'GPSDestLongitudeRef' => Exif::ASCII, # Reference for longitude of destination #p57
00278 'GPSDestLongitude' => Exif::RATIONAL, # Longitude of destination
00279 'GPSDestBearingRef' => Exif::ASCII, # Reference for bearing of destination #p57
00280 'GPSDestBearing' => Exif::RATIONAL, # Bearing of destination
00281 'GPSDestDistanceRef' => Exif::ASCII, # Reference for distance to destination #p57-58
00282 'GPSDestDistance' => Exif::RATIONAL, # Distance to destination
00283 'GPSProcessingMethod' => Exif::UNDEFINED, # Name of GPS processing method
00284 'GPSAreaInformation' => Exif::UNDEFINED, # Name of GPS area
00285 'GPSDateStamp' => Exif::ASCII, # GPS date
00286 'GPSDifferential' => Exif::SHORT, # GPS differential correction
00287 ),
00288 );
00289
00290 $this->file = $file;
00291 $this->basename = wfBaseName( $this->file );
00292
00293 $this->makeFlatExifTags();
00294
00295 $this->debugFile( $this->basename, __FUNCTION__, true );
00296 wfSuppressWarnings();
00297 $data = exif_read_data( $this->file );
00298 wfRestoreWarnings();
00304 $this->mRawExifData = $data ? $data : array();
00305
00306 $this->makeFilteredData();
00307 $this->makeFormattedData();
00308
00309 $this->debugFile( __FUNCTION__, false );
00310 }
00311
00318 function makeFlatExifTags() {
00319 $this->extractTags( $this->mExifTags );
00320 }
00321
00328 function extractTags( &$tagset ) {
00329 foreach( $tagset as $key => $val ) {
00330 if( is_array( $val ) ) {
00331 $this->extractTags( $val );
00332 } else {
00333 $this->mFlatExifTags[$key] = $val;
00334 }
00335 }
00336 }
00337
00341 function makeFilteredData() {
00342 $this->mFilteredExifData = $this->mRawExifData;
00343
00344 foreach( $this->mFilteredExifData as $k => $v ) {
00345 if ( !in_array( $k, array_keys( $this->mFlatExifTags ) ) ) {
00346 $this->debug( $v, __FUNCTION__, "'$k' is not a valid Exif tag" );
00347 unset( $this->mFilteredExifData[$k] );
00348 }
00349 }
00350
00351 foreach( $this->mFilteredExifData as $k => $v ) {
00352 if ( !$this->validate($k, $v) ) {
00353 $this->debug( $v, __FUNCTION__, "'$k' contained invalid data" );
00354 unset( $this->mFilteredExifData[$k] );
00355 }
00356 }
00357 }
00358
00362 function makeFormattedData( ) {
00363 $format = new FormatExif( $this->getFilteredData() );
00364 $this->mFormattedExifData = $format->getFormattedData();
00365 }
00374 function getData() {
00375 return $this->mRawExifData;
00376 }
00377
00381 function getFilteredData() {
00382 return $this->mFilteredExifData;
00383 }
00384
00388 function getFormattedData() {
00389 return $this->mFormattedExifData;
00390 }
00405 public static function version() {
00406 return 1;
00407 }
00408
00417 function isByte( $in ) {
00418 if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 255 ) {
00419 $this->debug( $in, __FUNCTION__, true );
00420 return true;
00421 } else {
00422 $this->debug( $in, __FUNCTION__, false );
00423 return false;
00424 }
00425 }
00426
00427 function isASCII( $in ) {
00428 if ( is_array( $in ) ) {
00429 return false;
00430 }
00431
00432 if ( preg_match( "/[^\x0a\x20-\x7e]/", $in ) ) {
00433 $this->debug( $in, __FUNCTION__, 'found a character not in our whitelist' );
00434 return false;
00435 }
00436
00437 if ( preg_match( '/^\s*$/', $in ) ) {
00438 $this->debug( $in, __FUNCTION__, 'input consisted solely of whitespace' );
00439 return false;
00440 }
00441
00442 return true;
00443 }
00444
00445 function isShort( $in ) {
00446 if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) {
00447 $this->debug( $in, __FUNCTION__, true );
00448 return true;
00449 } else {
00450 $this->debug( $in, __FUNCTION__, false );
00451 return false;
00452 }
00453 }
00454
00455 function isLong( $in ) {
00456 if ( !is_array( $in ) && sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) {
00457 $this->debug( $in, __FUNCTION__, true );
00458 return true;
00459 } else {
00460 $this->debug( $in, __FUNCTION__, false );
00461 return false;
00462 }
00463 }
00464
00465 function isRational( $in ) {
00466 $m = array();
00467 if ( !is_array( $in ) && @preg_match( '/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m ) ) { # Avoid division by zero
00468 return $this->isLong( $m[1] ) && $this->isLong( $m[2] );
00469 } else {
00470 $this->debug( $in, __FUNCTION__, 'fed a non-fraction value' );
00471 return false;
00472 }
00473 }
00474
00475 function isUndefined( $in ) {
00476 if ( !is_array( $in ) && preg_match( '/^\d{4}$/', $in ) ) {
00477 $this->debug( $in, __FUNCTION__, true );
00478 return true;
00479 } else {
00480 $this->debug( $in, __FUNCTION__, false );
00481 return false;
00482 }
00483 }
00484
00485 function isSlong( $in ) {
00486 if ( $this->isLong( abs( $in ) ) ) {
00487 $this->debug( $in, __FUNCTION__, true );
00488 return true;
00489 } else {
00490 $this->debug( $in, __FUNCTION__, false );
00491 return false;
00492 }
00493 }
00494
00495 function isSrational( $in ) {
00496 $m = array();
00497 if ( !is_array( $in ) && preg_match( '/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/', $in, $m ) ) { # Avoid division by zero
00498 return $this->isSlong( $m[0] ) && $this->isSlong( $m[1] );
00499 } else {
00500 $this->debug( $in, __FUNCTION__, 'fed a non-fraction value' );
00501 return false;
00502 }
00503 }
00515 function validate( $tag, $val ) {
00516 $debug = "tag is '$tag'";
00517
00518 switch( (string)$this->mFlatExifTags[$tag] ) {
00519 case (string)Exif::BYTE:
00520 $this->debug( $val, __FUNCTION__, $debug );
00521 return $this->isByte( $val );
00522 case (string)Exif::ASCII:
00523 $this->debug( $val, __FUNCTION__, $debug );
00524 return $this->isASCII( $val );
00525 case (string)Exif::SHORT:
00526 $this->debug( $val, __FUNCTION__, $debug );
00527 return $this->isShort( $val );
00528 case (string)Exif::LONG:
00529 $this->debug( $val, __FUNCTION__, $debug );
00530 return $this->isLong( $val );
00531 case (string)Exif::RATIONAL:
00532 $this->debug( $val, __FUNCTION__, $debug );
00533 return $this->isRational( $val );
00534 case (string)Exif::UNDEFINED:
00535 $this->debug( $val, __FUNCTION__, $debug );
00536 return $this->isUndefined( $val );
00537 case (string)Exif::SLONG:
00538 $this->debug( $val, __FUNCTION__, $debug );
00539 return $this->isSlong( $val );
00540 case (string)Exif::SRATIONAL:
00541 $this->debug( $val, __FUNCTION__, $debug );
00542 return $this->isSrational( $val );
00543 case (string)Exif::SHORT.','.Exif::LONG:
00544 $this->debug( $val, __FUNCTION__, $debug );
00545 return $this->isShort( $val ) || $this->isLong( $val );
00546 default:
00547 $this->debug( $val, __FUNCTION__, "The tag '$tag' is unknown" );
00548 return false;
00549 }
00550 }
00551
00561 function debug( $in, $fname, $action = NULL ) {
00562 if ( !$this->log ) {
00563 return;
00564 }
00565 $type = gettype( $in );
00566 $class = ucfirst( __CLASS__ );
00567 if ( $type === 'array' )
00568 $in = print_r( $in, true );
00569
00570 if ( $action === true )
00571 wfDebugLog( $this->log, "$class::$fname: accepted: '$in' (type: $type)\n");
00572 elseif ( $action === false )
00573 wfDebugLog( $this->log, "$class::$fname: rejected: '$in' (type: $type)\n");
00574 elseif ( $action === null )
00575 wfDebugLog( $this->log, "$class::$fname: input was: '$in' (type: $type)\n");
00576 else
00577 wfDebugLog( $this->log, "$class::$fname: $action (type: $type; content: '$in')\n");
00578 }
00579
00588 function debugFile( $fname, $io ) {
00589 if ( !$this->log ) {
00590 return;
00591 }
00592 $class = ucfirst( __CLASS__ );
00593 if ( $io ) {
00594 wfDebugLog( $this->log, "$class::$fname: begin processing: '{$this->basename}'\n" );
00595 } else {
00596 wfDebugLog( $this->log, "$class::$fname: end processing: '{$this->basename}'\n" );
00597 }
00598 }
00599
00600 }
00601
00606 class FormatExif {
00613 var $mExif;
00614
00621 function FormatExif( $exif ) {
00622 $this->mExif = $exif;
00623 }
00624
00633 function getFormattedData() {
00634 global $wgLang;
00635
00636 $tags =& $this->mExif;
00637
00638 $resolutionunit = !isset( $tags['ResolutionUnit'] ) || $tags['ResolutionUnit'] == 2 ? 2 : 3;
00639 unset( $tags['ResolutionUnit'] );
00640
00641 foreach( $tags as $tag => $val ) {
00642 switch( $tag ) {
00643 case 'Compression':
00644 switch( $val ) {
00645 case 1: case 6:
00646 $tags[$tag] = $this->msg( $tag, $val );
00647 break;
00648 default:
00649 $tags[$tag] = $val;
00650 break;
00651 }
00652 break;
00653
00654 case 'PhotometricInterpretation':
00655 switch( $val ) {
00656 case 2: case 6:
00657 $tags[$tag] = $this->msg( $tag, $val );
00658 break;
00659 default:
00660 $tags[$tag] = $val;
00661 break;
00662 }
00663 break;
00664
00665 case 'Orientation':
00666 switch( $val ) {
00667 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
00668 $tags[$tag] = $this->msg( $tag, $val );
00669 break;
00670 default:
00671 $tags[$tag] = $val;
00672 break;
00673 }
00674 break;
00675
00676 case 'PlanarConfiguration':
00677 switch( $val ) {
00678 case 1: case 2:
00679 $tags[$tag] = $this->msg( $tag, $val );
00680 break;
00681 default:
00682 $tags[$tag] = $val;
00683 break;
00684 }
00685 break;
00686
00687
00688
00689
00690 case 'XResolution':
00691 case 'YResolution':
00692 switch( $resolutionunit ) {
00693 case 2:
00694 $tags[$tag] = $this->msg( 'XYResolution', 'i', $this->formatNum( $val ) );
00695 break;
00696 case 3:
00697 $this->msg( 'XYResolution', 'c', $this->formatNum( $val ) );
00698 break;
00699 default:
00700 $tags[$tag] = $val;
00701 break;
00702 }
00703 break;
00704
00705
00706 case 'ExifVersion': case 'FlashpixVersion':
00707 $tags[$tag] = "$val"/100;
00708 break;
00709
00710 case 'ColorSpace':
00711 switch( $val ) {
00712 case 1: case 'FFFF.H':
00713 $tags[$tag] = $this->msg( $tag, $val );
00714 break;
00715 default:
00716 $tags[$tag] = $val;
00717 break;
00718 }
00719 break;
00720
00721 case 'ComponentsConfiguration':
00722 switch( $val ) {
00723 case 0: case 1: case 2: case 3: case 4: case 5: case 6:
00724 $tags[$tag] = $this->msg( $tag, $val );
00725 break;
00726 default:
00727 $tags[$tag] = $val;
00728 break;
00729 }
00730 break;
00731
00732 case 'DateTime':
00733 case 'DateTimeOriginal':
00734 case 'DateTimeDigitized':
00735 if( $val == '0000:00:00 00:00:00' ) {
00736 $tags[$tag] = wfMsg('exif-unknowndate');
00737 } elseif( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d) (?:\d\d):(?:\d\d):(?:\d\d)$/', $val ) ) {
00738 $tags[$tag] = $wgLang->timeanddate( wfTimestamp(TS_MW, $val) );
00739 }
00740 break;
00741
00742 case 'ExposureProgram':
00743 switch( $val ) {
00744 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
00745 $tags[$tag] = $this->msg( $tag, $val );
00746 break;
00747 default:
00748 $tags[$tag] = $val;
00749 break;
00750 }
00751 break;
00752
00753 case 'SubjectDistance':
00754 $tags[$tag] = $this->msg( $tag, '', $this->formatNum( $val ) );
00755 break;
00756
00757 case 'MeteringMode':
00758 switch( $val ) {
00759 case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 255:
00760 $tags[$tag] = $this->msg( $tag, $val );
00761 break;
00762 default:
00763 $tags[$tag] = $val;
00764 break;
00765 }
00766 break;
00767
00768 case 'LightSource':
00769 switch( $val ) {
00770 case 0: case 1: case 2: case 3: case 4: case 9: case 10: case 11:
00771 case 12: case 13: case 14: case 15: case 17: case 18: case 19: case 20:
00772 case 21: case 22: case 23: case 24: case 255:
00773 $tags[$tag] = $this->msg( $tag, $val );
00774 break;
00775 default:
00776 $tags[$tag] = $val;
00777 break;
00778 }
00779 break;
00780
00781 case 'Flash':
00782 $flashDecode = array(
00783 'fired' => $val & bindec( '00000001' ),
00784 'return' => ($val & bindec( '00000110' )) >> 1,
00785 'mode' => ($val & bindec( '00011000' )) >> 3,
00786 'function' => ($val & bindec( '00100000' )) >> 5,
00787 'redeye' => ($val & bindec( '01000000' )) >> 6,
00788
00789 );
00790
00791 # We do not need to handle unknown values since all are used.
00792 foreach( $flashDecode as $subTag => $subValue ) {
00793 # We do not need any message for zeroed values.
00794 if( $subTag != 'fired' && $subValue == 0) {
00795 continue;
00796 }
00797 $fullTag = $tag . '-' . $subTag ;
00798 $flashMsgs[] = $this->msg( $fullTag, $subValue );
00799 }
00800 $tags[$tag] = $wgLang->commaList( $flashMsgs );
00801 break;
00802
00803 case 'FocalPlaneResolutionUnit':
00804 switch( $val ) {
00805 case 2:
00806 $tags[$tag] = $this->msg( $tag, $val );
00807 break;
00808 default:
00809 $tags[$tag] = $val;
00810 break;
00811 }
00812 break;
00813
00814 case 'SensingMethod':
00815 switch( $val ) {
00816 case 1: case 2: case 3: case 4: case 5: case 7: case 8:
00817 $tags[$tag] = $this->msg( $tag, $val );
00818 break;
00819 default:
00820 $tags[$tag] = $val;
00821 break;
00822 }
00823 break;
00824
00825 case 'FileSource':
00826 switch( $val ) {
00827 case 3:
00828 $tags[$tag] = $this->msg( $tag, $val );
00829 break;
00830 default:
00831 $tags[$tag] = $val;
00832 break;
00833 }
00834 break;
00835
00836 case 'SceneType':
00837 switch( $val ) {
00838 case 1:
00839 $tags[$tag] = $this->msg( $tag, $val );
00840 break;
00841 default:
00842 $tags[$tag] = $val;
00843 break;
00844 }
00845 break;
00846
00847 case 'CustomRendered':
00848 switch( $val ) {
00849 case 0: case 1:
00850 $tags[$tag] = $this->msg( $tag, $val );
00851 break;
00852 default:
00853 $tags[$tag] = $val;
00854 break;
00855 }
00856 break;
00857
00858 case 'ExposureMode':
00859 switch( $val ) {
00860 case 0: case 1: case 2:
00861 $tags[$tag] = $this->msg( $tag, $val );
00862 break;
00863 default:
00864 $tags[$tag] = $val;
00865 break;
00866 }
00867 break;
00868
00869 case 'WhiteBalance':
00870 switch( $val ) {
00871 case 0: case 1:
00872 $tags[$tag] = $this->msg( $tag, $val );
00873 break;
00874 default:
00875 $tags[$tag] = $val;
00876 break;
00877 }
00878 break;
00879
00880 case 'SceneCaptureType':
00881 switch( $val ) {
00882 case 0: case 1: case 2: case 3:
00883 $tags[$tag] = $this->msg( $tag, $val );
00884 break;
00885 default:
00886 $tags[$tag] = $val;
00887 break;
00888 }
00889 break;
00890
00891 case 'GainControl':
00892 switch( $val ) {
00893 case 0: case 1: case 2: case 3: case 4:
00894 $tags[$tag] = $this->msg( $tag, $val );
00895 break;
00896 default:
00897 $tags[$tag] = $val;
00898 break;
00899 }
00900 break;
00901
00902 case 'Contrast':
00903 switch( $val ) {
00904 case 0: case 1: case 2:
00905 $tags[$tag] = $this->msg( $tag, $val );
00906 break;
00907 default:
00908 $tags[$tag] = $val;
00909 break;
00910 }
00911 break;
00912
00913 case 'Saturation':
00914 switch( $val ) {
00915 case 0: case 1: case 2:
00916 $tags[$tag] = $this->msg( $tag, $val );
00917 break;
00918 default:
00919 $tags[$tag] = $val;
00920 break;
00921 }
00922 break;
00923
00924 case 'Sharpness':
00925 switch( $val ) {
00926 case 0: case 1: case 2:
00927 $tags[$tag] = $this->msg( $tag, $val );
00928 break;
00929 default:
00930 $tags[$tag] = $val;
00931 break;
00932 }
00933 break;
00934
00935 case 'SubjectDistanceRange':
00936 switch( $val ) {
00937 case 0: case 1: case 2: case 3:
00938 $tags[$tag] = $this->msg( $tag, $val );
00939 break;
00940 default:
00941 $tags[$tag] = $val;
00942 break;
00943 }
00944 break;
00945
00946 case 'GPSLatitudeRef':
00947 case 'GPSDestLatitudeRef':
00948 switch( $val ) {
00949 case 'N': case 'S':
00950 $tags[$tag] = $this->msg( 'GPSLatitude', $val );
00951 break;
00952 default:
00953 $tags[$tag] = $val;
00954 break;
00955 }
00956 break;
00957
00958 case 'GPSLongitudeRef':
00959 case 'GPSDestLongitudeRef':
00960 switch( $val ) {
00961 case 'E': case 'W':
00962 $tags[$tag] = $this->msg( 'GPSLongitude', $val );
00963 break;
00964 default:
00965 $tags[$tag] = $val;
00966 break;
00967 }
00968 break;
00969
00970 case 'GPSStatus':
00971 switch( $val ) {
00972 case 'A': case 'V':
00973 $tags[$tag] = $this->msg( $tag, $val );
00974 break;
00975 default:
00976 $tags[$tag] = $val;
00977 break;
00978 }
00979 break;
00980
00981 case 'GPSMeasureMode':
00982 switch( $val ) {
00983 case 2: case 3:
00984 $tags[$tag] = $this->msg( $tag, $val );
00985 break;
00986 default:
00987 $tags[$tag] = $val;
00988 break;
00989 }
00990 break;
00991
00992 case 'GPSSpeedRef':
00993 case 'GPSDestDistanceRef':
00994 switch( $val ) {
00995 case 'K': case 'M': case 'N':
00996 $tags[$tag] = $this->msg( 'GPSSpeed', $val );
00997 break;
00998 default:
00999 $tags[$tag] = $val;
01000 break;
01001 }
01002 break;
01003
01004 case 'GPSTrackRef':
01005 case 'GPSImgDirectionRef':
01006 case 'GPSDestBearingRef':
01007 switch( $val ) {
01008 case 'T': case 'M':
01009 $tags[$tag] = $this->msg( 'GPSDirection', $val );
01010 break;
01011 default:
01012 $tags[$tag] = $val;
01013 break;
01014 }
01015 break;
01016
01017 case 'GPSDateStamp':
01018 $tags[$tag] = $wgLang->date( substr( $val, 0, 4 ) . substr( $val, 5, 2 ) . substr( $val, 8, 2 ) . '000000' );
01019 break;
01020
01021
01022
01023
01024 case 'Make':
01025 case 'Model':
01026 case 'Software':
01027 $tags[$tag] = $this->msg( $tag, '', $val );
01028 break;
01029
01030 case 'ExposureTime':
01031
01032 $tags[$tag] = wfMsg( 'exif-exposuretime-format',
01033 $this->formatFraction( $val ), $this->formatNum( $val ) );
01034 break;
01035
01036 case 'FNumber':
01037 $tags[$tag] = wfMsg( 'exif-fnumber-format',
01038 $this->formatNum( $val ) );
01039 break;
01040
01041 case 'FocalLength':
01042 $tags[$tag] = wfMsg( 'exif-focallength-format',
01043 $this->formatNum( $val ) );
01044 break;
01045
01046 default:
01047 $tags[$tag] = $this->formatNum( $val );
01048 break;
01049 }
01050 }
01051
01052 return $tags;
01053 }
01054
01065 function msg( $tag, $val, $arg = null ) {
01066 global $wgContLang;
01067
01068 if ($val === '')
01069 $val = 'value';
01070 return wfMsg( $wgContLang->lc( "exif-$tag-$val" ), $arg );
01071 }
01072
01082 function formatNum( $num ) {
01083 $m = array();
01084 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) )
01085 return $m[2] != 0 ? $m[1] / $m[2] : $num;
01086 else
01087 return $num;
01088 }
01089
01098 function formatFraction( $num ) {
01099 $m = array();
01100 if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) ) {
01101 $numerator = intval( $m[1] );
01102 $denominator = intval( $m[2] );
01103 $gcd = $this->gcd( $numerator, $denominator );
01104 if( $gcd != 0 ) {
01105
01106 return $numerator / $gcd . '/' . $denominator / $gcd;
01107 }
01108 }
01109 return $this->formatNum( $num );
01110 }
01111
01120 function gcd( $a, $b ) {
01121
01122
01123
01124
01125
01126
01127
01128
01129 while( $b != 0 ) {
01130 $remainder = $a % $b;
01131
01132
01133 $a = $b;
01134 $b = $remainder;
01135 }
01136 return $a;
01137 }
01138 }
01139
01143 define( 'MW_EXIF_BYTE', Exif::BYTE );
01144 define( 'MW_EXIF_ASCII', Exif::ASCII );
01145 define( 'MW_EXIF_SHORT', Exif::SHORT );
01146 define( 'MW_EXIF_LONG', Exif::LONG );
01147 define( 'MW_EXIF_RATIONAL', Exif::RATIONAL );
01148 define( 'MW_EXIF_UNDEFINED', Exif::UNDEFINED );
01149 define( 'MW_EXIF_SLONG', Exif::SLONG );
01150 define( 'MW_EXIF_SRATIONAL', Exif::SRATIONAL );