/**
* Constructor
+ *
+ * @param string $file
*/
function Exif( $file ) {
/**
'SpatialFrequencyResponse' => MW_EXIF_UNDEFINED, # Spatial frequency response
'FocalPlaneXResolution' => MW_EXIF_RATIONAL, # Focal plane X resolution
'FocalPlaneYResolution' => MW_EXIF_RATIONAL, # Focal plane Y resolution
- 'FocalPlaneResolutionUnit' => MW_EXIF_SHORT, # Focal plane resolution unit
+ 'FocalPlaneResolutionUnit' => MW_EXIF_SHORT, # Focal plane resolution unit #p46
'SubjectLocation' => MW_EXIF_SHORT, # Subject location
'ExposureIndex' => MW_EXIF_RATIONAL, # Exposure index
'SensingMethod' => MW_EXIF_SHORT, # Sensing method #p46
}
}
- /**#@-*/
-
/**
* Make $this->mFilteredExifData
*/
/**#@+
* Validates if a tag value is of the type it should be according to the Exif spec
- *
+ *
+ * @access private
+ *
* @param mixed $in The input value to check
* @return bool
*/
function isByte( $in ) {
- if ( sprintf('%d', $in) === $in && $in >= 0 && $in <= 255 ) {
+ if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 255 ) {
$this->debug( $in, __FUNCTION__, true );
return true;
} else {
}
function isShort( $in ) {
- if ( sprintf('%d', $in) === $in && $in >= 0 && $in <= 65536 ) {
+ if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 65536 ) {
$this->debug( $in, __FUNCTION__, true );
return true;
} else {
- $this->debug( $in, __FUNCTION__, true );
+ $this->debug( $in, __FUNCTION__, false );
return false;
}
}
function isLong( $in ) {
- if ( sprintf('%d', $in) === $in && $in >= 0 && $in <= 4294967296 ) {
+ if ( sprintf('%d', $in) == $in && $in >= 0 && $in <= 4294967296 ) {
$this->debug( $in, __FUNCTION__, true );
return true;
} else {
}
function isRational( $in ) {
- if ( preg_match( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
+ if ( @preg_match( "/^(\d+)\/(\d+[1-9]|[1-9]\d*)$/", $in, $m ) ) { # Avoid division by zero
return $this->isLong( $m[1] ) && $this->isLong( $m[2] );
} else {
$this->debug( $in, __FUNCTION__, 'fed a non-fraction value' );
}
function isUndefined( $in ) {
- $this->debug( $in, __FUNCTION__ );
if ( preg_match( "/^\d{4}$/", $in ) ) { // Allow ExifVersion and FlashpixVersion
+ $this->debug( $in, __FUNCTION__, true );
return true;
} else {
+ $this->debug( $in, __FUNCTION__, false );
return false;
}
}
/**
* Validates if a tag has a legal value according to the Exif spec
*
+ * @access private
+ *
* @param string $tag The tag to check
* @param mixed $val The value of the tag
* @return bool
*/
function validate( $tag, $val ) {
+ $debug = "tag is '$tag'";
// Fucks up if not typecast
switch( (string)$this->mFlatExifTags[$tag] ) {
case (string)MW_EXIF_BYTE:
+ $this->debug( $val, __FUNCTION__, $debug );
return $this->isByte( $val );
case (string)MW_EXIF_ASCII:
+ $this->debug( $val, __FUNCTION__, $debug );
return $this->isASCII( $val );
case (string)MW_EXIF_SHORT:
+ $this->debug( $val, __FUNCTION__, $debug );
return $this->isShort( $val );
case (string)MW_EXIF_LONG:
+ $this->debug( $val, __FUNCTION__, $debug );
return $this->isLong( $val );
case (string)MW_EXIF_RATIONAL:
+ $this->debug( $val, __FUNCTION__, $debug );
return $this->isRational( $val );
case (string)MW_EXIF_UNDEFINED:
+ $this->debug( $val, __FUNCTION__, $debug );
return $this->isUndefined( $val );
case (string)MW_EXIF_SLONG:
+ $this->debug( $val, __FUNCTION__, $debug );
return $this->isSlong( $val );
case (string)MW_EXIF_SRATIONAL:
+ $this->debug( $val, __FUNCTION__, $debug );
return $this->isSrational( $val );
case (string)MW_EXIF_SHORT.','.MW_EXIF_LONG:
+ $this->debug( $val, __FUNCTION__, $debug );
return $this->isShort( $val ) || $this->isLong( $val );
default:
$this->debug( $val, __FUNCTION__, "The tag '$tag' is unknown" );
/**
* Conviniance function for debugging output
*
+ * @access private
+ *
* @param mixed $in
* @param string $fname
* @param mixed $action
* @access private
*/
var $mExif;
-
+
/**
* Constructor
*
global $wgLang;
$tags =& $this->mExif;
+
+ $resolutionunit = !isset( $tags['ResolutionUnit'] ) || $tags['ResolutionUnit'] == 2 ? 2 : 3;
+ unset( $tags['ResolutionUnit'] );
foreach( $tags as $tag => $val ) {
switch( $tag ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'PhotometricInterpretation':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'Orientation':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'PlanarConfiguration':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
// TODO: YCbCrSubSampling
// TODO: YCbCrPositioning
- // TODO: If this field does not exists use 2
- case 'ResolutionUnit': #p26
- switch( $val ) {
- case 2: case 3:
- $tags[$tag] = $this->msg( $tag, $val );
- break;
- default:
- $tags[$tag] = $val;
- break;
- }
+ case 'XResolution':
+ case 'YResolution':
+ switch( $resolutionunit ) {
+ case 2:
+ $tags[$tag] = $this->msg( 'XYResolution', 'i', $this->formatNum( $val ) );
+ break;
+ case 3:
+ $this->msg( 'XYResolution', 'c', $this->formatNum( $val ) );
+ break;
+ default:
+ $tags[$tag] = $val;
+ break;
+ }
+ break;
+
// TODO: YCbCrCoefficients #p27 (see annex E)
case 'ExifVersion': case 'FlashpixVersion':
$tags[$tag] = "$val"/100;
$tags[$tag] = $val;
break;
}
+ break;
case 'ComponentsConfiguration':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'DateTime':
case 'DateTimeOriginal':
$tags[$tag] = $val;
break;
}
+ break;
+
+ case 'SubjectDistance':
+ $tags[$tag] = $this->msg( $tag, '', $this->formatNum( $val ) );
+ break;
case 'MeteringMode':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'LightSource':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
// TODO: Flash
+ case 'FocalPlaneResolutionUnit':
+ switch( $val ) {
+ case 2:
+ $tags[$tag] = $this->msg( $tag, $val );
+ break;
+ default:
+ $tags[$tag] = $val;
+ break;
+ }
+ break;
+
case 'SensingMethod':
switch( $val ) {
case 1: case 2: case 3: case 4: case 5: case 7: case 8:
$tags[$tag] = $val;
break;
}
+ break;
case 'FileSource':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'SceneType':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'CustomRendered':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'ExposureMode':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'WhiteBalance':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'SceneCaptureType':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'GainControl':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'Contrast':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'Saturation':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'Sharpness':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'SubjectDistanceRange':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'GPSLatitudeRef':
case 'GPSDestLatitudeRef':
$tags[$tag] = $val;
break;
}
+ break;
case 'GPSLongitudeRef':
case 'GPSDestLongitudeRef':
$tags[$tag] = $val;
break;
}
+ break;
case 'GPSStatus':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'GPSMeasureMode':
switch( $val ) {
$tags[$tag] = $val;
break;
}
+ break;
case 'GPSSpeedRef':
case 'GPSDestDistanceRef':
$tags[$tag] = $val;
break;
}
+ break;
case 'GPSTrackRef':
case 'GPSImgDirectionRef':
$tags[$tag] = $val;
break;
}
+ break;
case 'GPSDateStamp':
$tags[$tag] = $wgLang->date( substr( $val, 0, 4 ) . substr( $val, 5, 2 ) . substr( $val, 8, 2 ) . '000000' );
case 'Make':
case 'Model':
case 'Software':
- $tags[$tag] = wfMsg( strtolower( "exif-$tag-value" ), $val );
+ $tags[$tag] = $this->msg( $tag, '', $val );
break;
default:
- if ( preg_match( '/^(\d+)\/(\d+)$/', $val, $m ) ) {
- $tags[$tag] = $m[2] != 0 ? $m[1]/$m[2] : $val;
- break;
- }
- $tags[$tag] = $val;
+ $tags[$tag] = $this->formatNum( $val );
break;
}
}
}
/**
- * Conviniance function for format()
+ * Conviniance function for getFormattedData()
+ *
+ * @access private
*
* @param string $tag The tag name to pass on
* @param string $val The value of the tag
+ * @param string $arg An argument to pass ($1)
* @return string A wfMsg of "exif-$tag-$val" in lower case
*/
- function msg( $tag, $val ) {
- return wfMsg( strtolower("exif-$tag-$val") );
+ function msg( $tag, $val, $arg = null ) {
+ if ($val === '')
+ $val = 'value';
+ return wfMsg( strtolower( "exif-$tag-$val" ), $arg );
+ }
+
+ /**
+ * Format a number, convert numbers from fractions into floating point
+ * numbers
+ *
+ * @access private
+ *
+ * @param mixed $num The value to format
+ * @return mixed A floating point number or whatever we were fed
+ */
+ function formatNum( $num ) {
+ if ( preg_match( '/^(\d+)\/(\d+)$/', $num, $m ) )
+ return $m[2] != 0 ? $m[1] / $m[2] : $num;
+ else
+ return $num;
}
}