XCF format: code style/comment
authorAntoine Musso <hashar@users.mediawiki.org>
Wed, 4 Jan 2012 13:37:28 +0000 (13:37 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Wed, 4 Jan 2012 13:37:28 +0000 (13:37 +0000)
* Saved a level of indentation by returning early on command failure
* $md -> $metadata

Follow r107351

includes/media/XCF.php

index f8143a4..837c855 100644 (file)
@@ -1,6 +1,11 @@
 <?php
 /**
- * Handler for the Gimp's native file format
+ * Handler for the Gimp's native file format (XCF)
+ *
+ * Overview:
+ *   http://en.wikipedia.org/wiki/XCF_(file_format)
+ * Specification in Gnome repository:
+ *   http://svn.gnome.org/viewvc/gimp/trunk/devel-docs/xcf.txt?view=markup
  *
  * @file
  * @ingroup Media
@@ -27,7 +32,7 @@ class XCFHandler extends BitmapHandler {
        }
 
        /**
-        * Get width and height from the bmp header.
+        * Get width and height from the XCF header.
         *
         * @param $image
         * @param $filename
@@ -40,46 +45,54 @@ class XCFHandler extends BitmapHandler {
        static function getXCFMetaData( $filename ) {
                global $wgImageMagickIdentifyCommand;
 
-               $md = false;
                $cmd = wfEscapeShellArg( $wgImageMagickIdentifyCommand ) . ' -verbose ' . wfEscapeShellArg( $filename );
                wfDebug( __METHOD__ . ": Running $cmd \n" );
-               $retval = '';
+
+               $retval = null;
                $return = wfShellExec( $cmd, $retval );
+               if( $retval !== 0 ) {
+                       wfDebug( __METHOD__ . ": error encountered while running $cmd\n" );
+                       return false;
+               }
 
-               if( $retval == 0 ) {
-                       $colorspace = preg_match_all( '/ *Colorspace: RGB/', $return, $match );
-                       $frameCount = preg_match_all( '/ *Geometry: ([0-9]+x[0-9]+)\+[+0-9]*/', $return, $match );
-                       wfDebug( __METHOD__ . ": Got $frameCount matches\n" );
+               $colorspace = preg_match_all( '/ *Colorspace: RGB/', $return, $match );
+               $frameCount = preg_match_all( '/ *Geometry: ([0-9]+x[0-9]+)\+[+0-9]*/', $return, $match );
+               wfDebug( __METHOD__ . ": Got $frameCount matches\n" );
 
-                       /* if( $frameCount == 1 ) { */
-                       /*      preg_match( '/([0-9]+)x([0-9]+)/sm', $match[1][0], $m ); */
-                       /*      $sizeX = $m[1]; */
-                       /*      $sizeY = $m[2]; */
-                       /* } else { */
-                               $sizeX = 0;
-                               $sizeY = 0;
+               /* if( $frameCount == 1 ) { */
+               /*      preg_match( '/([0-9]+)x([0-9]+)/sm', $match[1][0], $m ); */
+               /*      $sizeX = $m[1]; */
+               /*      $sizeY = $m[2]; */
+               /* } else { */
+                       $sizeX = 0;
+                       $sizeY = 0;
 
-                               foreach( $match[1] as $res ) {
-                                       preg_match( '/([0-9]+)x([0-9]+)/sm', $res, $m );
-                                       if( $m[1] > $sizeX ) {
-                                               $sizeX = $m[1];
-                                       }
-                                       if( $m[2] > $sizeY ) {
-                                               $sizeY = $m[2];
-                                       }
+                       # Find out the largest width and height used in any frame
+                       foreach( $match[1] as $res ) {
+                               preg_match( '/([0-9]+)x([0-9]+)/sm', $res, $m );
+                               if( $m[1] > $sizeX ) {
+                                       $sizeX = $m[1];
+                               }
+                               if( $m[2] > $sizeY ) {
+                                       $sizeY = $m[2];
                                }
-                       /* } */
+                       }
+               /* } */
 
-                       wfDebug( __METHOD__ . ": Found $sizeX x $sizeY x $frameCount \n" );
-                       $md['frameCount'] = $frameCount;
-                       $md[0] = $sizeX;
-                       $md[1] = $sizeY;
-                       $md[2] = null;
-                       $md[3] = "height=\"$sizeY\" width=\"$sizeX\"";
-                       $md['mime'] = 'image/x-xcf';
-                       $md['channels'] = $colorspace == 1 ? 3 : 4;
-               }
-               return $md;
+               wfDebug( __METHOD__ . ": Found $sizeX x $sizeY x $frameCount \n" );
+
+               # Forge a return array containing metadata information just like getimagesize()
+               # See PHP documentation at: http://www.php.net/getimagesize
+               $metadata = array();
+               $metadata['frameCount'] = $frameCount;
+               $metadata[0] = $sizeX;
+               $metadata[1] = $sizeY;
+               $metadata[2] = null;
+               $metadata[3] = "height=\"$sizeY\" width=\"$sizeX\"";
+               $metadata['mime'] = 'image/x-xcf';
+               $metadata['channels'] = $colorspace == 1 ? 3 : 4;
+
+               return $metadata;
        }
 
        /**