* No longer displaying ResolutionUnit at all
[lhc/web/wiklou.git] / includes / Exif.php
index f826da9..7e90175 100644 (file)
@@ -84,6 +84,8 @@ class Exif {
 
        /**
         * Constructor
+        *
+        * @param string $file
         */
        function Exif( $file ) {
                /**
@@ -305,8 +307,6 @@ class Exif {
                }
        }
        
-       /**#@-*/
-       
        /**
         * Make $this->mFilteredExifData
         */
@@ -377,7 +377,9 @@ class Exif {
 
        /**#@+
         * 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
         */
@@ -472,6 +474,8 @@ class Exif {
        /**
         * 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
@@ -516,6 +520,8 @@ class Exif {
        /**
         * Conviniance function for debugging output
         *
+        * @access private
+        *
         * @param mixed $in 
         * @param string $fname
         * @param mixed $action
@@ -573,6 +579,9 @@ class FormatExif {
                global $wgLang;
                
                $tags =& $this->mExif;
+
+               $resolutionunit = !isset( $tags['ResolutionUnit'] ) || $tags['ResolutionUnit'] == 2 ? 2 : 3;
+               unset( $tags['ResolutionUnit'] );
                
                foreach( $tags as $tag => $val ) {
                        switch( $tag ) {
@@ -622,18 +631,22 @@ class FormatExif {
                        
                        // 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;
@@ -677,6 +690,10 @@ class FormatExif {
                                        break;
                                }
                                break;
+
+                       case 'SubjectDistance':
+                               $tags[$tag] = $this->msg( $tag, '', $this->formatNum( $val ) );
+                               break;
        
                        case 'MeteringMode':
                                switch( $val ) {
@@ -927,14 +944,10 @@ class FormatExif {
                        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;
                        }
                }
@@ -943,13 +956,34 @@ class FormatExif {
        }
 
        /**
-        * 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;
        }
 }