r107351: forgot to commit the changes to AutoLoader ... also update a comment
[lhc/web/wiklou.git] / includes / media / XCF.php
1 <?php
2 /**
3 * Handler for the Gimp's native file format
4 *
5 * @file
6 * @ingroup Media
7 */
8
9 /**
10 * Handler for the Gimp's native file format; getimagesize() doesn't
11 * support these files
12 *
13 * @ingroup Media
14 */
15 class XCFHandler extends BitmapHandler {
16
17 /**
18 * Render files as PNG
19 *
20 * @param $ext
21 * @param $mime
22 * @param $params
23 * @return array
24 */
25 function getThumbType( $ext, $mime, $params = null ) {
26 return array( 'png', 'image/png' );
27 }
28
29 /**
30 * Get width and height from the bmp header.
31 *
32 * @param $image
33 * @param $filename
34 * @return array
35 */
36 function getImageSize( $image, $filename ) {
37 return self::getXCFMetaData( $filename );
38 }
39
40 static function getXCFMetaData( $filename ) {
41 global $wgImageMagickIdentifyCommand;
42
43 $md = false;
44 $cmd = wfEscapeShellArg( $wgImageMagickIdentifyCommand ) . ' -verbose ' . wfEscapeShellArg( $filename );
45 wfDebug( __METHOD__ . ": Running $cmd \n" );
46 $retval = '';
47 $return = wfShellExec( $cmd, $retval );
48
49 if( $retval == 0 ) {
50 $colorspace = preg_match_all( '/ *Colorspace: RGB/', $return, $match );
51 $frameCount = preg_match_all( '/ *Geometry: ([0-9]+x[0-9]+)\+[+0-9]*/', $return, $match );
52 wfDebug( __METHOD__ . ": Got $frameCount matches\n" );
53
54 /* if( $frameCount == 1 ) { */
55 /* preg_match( '/([0-9]+)x([0-9]+)/sm', $match[1][0], $m ); */
56 /* $sizeX = $m[1]; */
57 /* $sizeY = $m[2]; */
58 /* } else { */
59 $sizeX = 0;
60 $sizeY = 0;
61
62 foreach( $match[1] as $res ) {
63 preg_match( '/([0-9]+)x([0-9]+)/sm', $res, $m );
64 if( $m[1] > $sizeX ) {
65 $sizeX = $m[1];
66 }
67 if( $m[2] > $sizeY ) {
68 $sizeY = $m[2];
69 }
70 }
71 /* } */
72
73 wfDebug( __METHOD__ . ": Found $sizeX x $sizeY x $frameCount \n" );
74 $md['frameCount'] = $frameCount;
75 $md[0] = $sizeX;
76 $md[1] = $sizeY;
77 $md[2] = null;
78 $md[3] = "height=\"$sizeY\" width=\"$sizeX\"";
79 $md['mime'] = 'image/x-xcf';
80 $md['channels'] = $colorspace == 1 ? 3 : 4;
81 }
82 return $md;
83 }
84
85 /**
86 * Must use "im" for XCF
87 *
88 * @return string
89 */
90 protected static function getScalerType( $dstPath, $checkDstPath = true ) {
91 return "im";
92 }
93 }