r108024 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108023‎ | r108024 | r108025 >
Date:13:37, 4 January 2012
Author:hashar
Status:ok
Tags:
Comment:
XCF format: code style/comment

* Saved a level of indentation by returning early on command failure
* $md -> $metadata

Follow r107351
Modified paths:
  • /trunk/phase3/includes/media/XCF.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/media/XCF.php
@@ -1,7 +1,12 @@
22 <?php
33 /**
4 - * Handler for the Gimp's native file format
 4+ * Handler for the Gimp's native file format (XCF)
55 *
 6+ * Overview:
 7+ * http://en.wikipedia.org/wiki/XCF_(file_format)
 8+ * Specification in Gnome repository:
 9+ * http://svn.gnome.org/viewvc/gimp/trunk/devel-docs/xcf.txt?view=markup
 10+ *
611 * @file
712 * @ingroup Media
813 */
@@ -27,7 +32,7 @@
2833 }
2934
3035 /**
31 - * Get width and height from the bmp header.
 36+ * Get width and height from the XCF header.
3237 *
3338 * @param $image
3439 * @param $filename
@@ -40,46 +45,54 @@
4146 static function getXCFMetaData( $filename ) {
4247 global $wgImageMagickIdentifyCommand;
4348
44 - $md = false;
4549 $cmd = wfEscapeShellArg( $wgImageMagickIdentifyCommand ) . ' -verbose ' . wfEscapeShellArg( $filename );
4650 wfDebug( __METHOD__ . ": Running $cmd \n" );
47 - $retval = '';
 51+
 52+ $retval = null;
4853 $return = wfShellExec( $cmd, $retval );
 54+ if( $retval !== 0 ) {
 55+ wfDebug( __METHOD__ . ": error encountered while running $cmd\n" );
 56+ return false;
 57+ }
4958
50 - if( $retval == 0 ) {
51 - $colorspace = preg_match_all( '/ *Colorspace: RGB/', $return, $match );
52 - $frameCount = preg_match_all( '/ *Geometry: ([0-9]+x[0-9]+)\+[+0-9]*/', $return, $match );
53 - wfDebug( __METHOD__ . ": Got $frameCount matches\n" );
 59+ $colorspace = preg_match_all( '/ *Colorspace: RGB/', $return, $match );
 60+ $frameCount = preg_match_all( '/ *Geometry: ([0-9]+x[0-9]+)\+[+0-9]*/', $return, $match );
 61+ wfDebug( __METHOD__ . ": Got $frameCount matches\n" );
5462
55 - /* if( $frameCount == 1 ) { */
56 - /* preg_match( '/([0-9]+)x([0-9]+)/sm', $match[1][0], $m ); */
57 - /* $sizeX = $m[1]; */
58 - /* $sizeY = $m[2]; */
59 - /* } else { */
60 - $sizeX = 0;
61 - $sizeY = 0;
 63+ /* if( $frameCount == 1 ) { */
 64+ /* preg_match( '/([0-9]+)x([0-9]+)/sm', $match[1][0], $m ); */
 65+ /* $sizeX = $m[1]; */
 66+ /* $sizeY = $m[2]; */
 67+ /* } else { */
 68+ $sizeX = 0;
 69+ $sizeY = 0;
6270
63 - foreach( $match[1] as $res ) {
64 - preg_match( '/([0-9]+)x([0-9]+)/sm', $res, $m );
65 - if( $m[1] > $sizeX ) {
66 - $sizeX = $m[1];
67 - }
68 - if( $m[2] > $sizeY ) {
69 - $sizeY = $m[2];
70 - }
 71+ # Find out the largest width and height used in any frame
 72+ foreach( $match[1] as $res ) {
 73+ preg_match( '/([0-9]+)x([0-9]+)/sm', $res, $m );
 74+ if( $m[1] > $sizeX ) {
 75+ $sizeX = $m[1];
7176 }
72 - /* } */
 77+ if( $m[2] > $sizeY ) {
 78+ $sizeY = $m[2];
 79+ }
 80+ }
 81+ /* } */
7382
74 - wfDebug( __METHOD__ . ": Found $sizeX x $sizeY x $frameCount \n" );
75 - $md['frameCount'] = $frameCount;
76 - $md[0] = $sizeX;
77 - $md[1] = $sizeY;
78 - $md[2] = null;
79 - $md[3] = "height=\"$sizeY\" width=\"$sizeX\"";
80 - $md['mime'] = 'image/x-xcf';
81 - $md['channels'] = $colorspace == 1 ? 3 : 4;
82 - }
83 - return $md;
 83+ wfDebug( __METHOD__ . ": Found $sizeX x $sizeY x $frameCount \n" );
 84+
 85+ # Forge a return array containing metadata information just like getimagesize()
 86+ # See PHP documentation at: http://www.php.net/getimagesize
 87+ $metadata = array();
 88+ $metadata['frameCount'] = $frameCount;
 89+ $metadata[0] = $sizeX;
 90+ $metadata[1] = $sizeY;
 91+ $metadata[2] = null;
 92+ $metadata[3] = "height=\"$sizeY\" width=\"$sizeX\"";
 93+ $metadata['mime'] = 'image/x-xcf';
 94+ $metadata['channels'] = $colorspace == 1 ? 3 : 4;
 95+
 96+ return $metadata;
8497 }
8598
8699 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r107351* First simple XCF thumbnailing. Convert from ImageMagick has buggy...mah00:46, 27 December 2011

Status & tagging log