Index: trunk/phase3/includes/media/XCF.php |
— | — | @@ -1,7 +1,12 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | | - * Handler for the Gimp's native file format |
| 4 | + * Handler for the Gimp's native file format (XCF) |
5 | 5 | * |
| 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 | + * |
6 | 11 | * @file |
7 | 12 | * @ingroup Media |
8 | 13 | */ |
— | — | @@ -27,7 +32,7 @@ |
28 | 33 | } |
29 | 34 | |
30 | 35 | /** |
31 | | - * Get width and height from the bmp header. |
| 36 | + * Get width and height from the XCF header. |
32 | 37 | * |
33 | 38 | * @param $image |
34 | 39 | * @param $filename |
— | — | @@ -40,46 +45,54 @@ |
41 | 46 | static function getXCFMetaData( $filename ) { |
42 | 47 | global $wgImageMagickIdentifyCommand; |
43 | 48 | |
44 | | - $md = false; |
45 | 49 | $cmd = wfEscapeShellArg( $wgImageMagickIdentifyCommand ) . ' -verbose ' . wfEscapeShellArg( $filename ); |
46 | 50 | wfDebug( __METHOD__ . ": Running $cmd \n" ); |
47 | | - $retval = ''; |
| 51 | + |
| 52 | + $retval = null; |
48 | 53 | $return = wfShellExec( $cmd, $retval ); |
| 54 | + if( $retval !== 0 ) { |
| 55 | + wfDebug( __METHOD__ . ": error encountered while running $cmd\n" ); |
| 56 | + return false; |
| 57 | + } |
49 | 58 | |
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" ); |
54 | 62 | |
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; |
62 | 70 | |
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]; |
71 | 76 | } |
72 | | - /* } */ |
| 77 | + if( $m[2] > $sizeY ) { |
| 78 | + $sizeY = $m[2]; |
| 79 | + } |
| 80 | + } |
| 81 | + /* } */ |
73 | 82 | |
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; |
84 | 97 | } |
85 | 98 | |
86 | 99 | /** |