* First simple XCF thumbnailing. Convert from ImageMagick has buggy
authorMark A. Hershberger <mah@users.mediawiki.org>
Tue, 27 Dec 2011 00:46:44 +0000 (00:46 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Tue, 27 Dec 2011 00:46:44 +0000 (00:46 +0000)
  support for XCF, though, so one of the solutions at
  http://stackoverflow.com/questions/5794640/how-to-convert-xcf-to-png-using-gimp-from-the-command-line
  is probably better.

* File::maybeDoTransform() since (at least) r106752 neglects what
  BitmapHandler::getThumbType() returns, so add support for that.

* Add $wgImageMagickIdentifyCommand to avoid writing a parser for XCF
  metadata.

includes/DefaultSettings.php
includes/filerepo/file/File.php
includes/media/Bitmap.php
includes/media/XCF.php [new file with mode: 0644]

index bd12a04..0f6dd0e 100644 (file)
@@ -620,6 +620,7 @@ $wgMediaHandlers = array(
        'image/tiff' => 'TiffHandler',
        'image/x-ms-bmp' => 'BmpHandler',
        'image/x-bmp' => 'BmpHandler',
+       'image/x-xcf' => 'XCFHandler',
        'image/svg+xml' => 'SvgHandler', // official
        'image/svg' => 'SvgHandler', // compat
        'image/vnd.djvu' => 'DjVuHandler', // official
@@ -638,6 +639,8 @@ $wgMediaHandlers = array(
 $wgUseImageMagick              = false;
 /** The convert command shipped with ImageMagick */
 $wgImageMagickConvertCommand    = '/usr/bin/convert';
+/** The identify command shipped with ImageMagick */
+$wgImageMagickIdentifyCommand   = '/usr/bin/identify';
 
 /** Sharpening parameter to ImageMagick */
 $wgSharpenParameter = '0x0.4';
index 04fa2f4..7cb9e27 100644 (file)
@@ -778,8 +778,11 @@ abstract class File {
                        wfDebug( __METHOD__ . " forcing rendering per flag File::RENDER_FORCE\n" );
                }
 
-               // Create a temp FS file with the same extension
-               $tmpFile = TempFSFile::factory( 'transform_', $this->getExtension() );
+               // Create a temp FS file with the same extension and the thumbnail
+               $extension = $this->getExtension();
+               list( $thumbExt, $thumbMime ) = $this->handler->getThumbType(
+                       $extension, $this->getMimeType(), $params );
+               $tmpFile = TempFSFile::factory( 'transform_', $this->getExtension() . '.' . $thumbExt );
                if ( !$tmpFile ) {
                        return new MediaTransformError( 'thumbnail_error',
                                $params['width'], 0, wfMsg( 'thumbnail-temp-create' ) );
index 0a4c55f..878ad58 100644 (file)
@@ -302,6 +302,8 @@ class BitmapHandler extends ImageHandler {
                                        $animation_post = '-fuzz 5% -layers optimizeTransparency';
                                }
                        }
+               } elseif ( $params['mimeType'] == 'image/x-xcf' ) {
+                       $animation_post = '-layers merge';
                }
 
                // Use one thread only, to avoid deadlock bugs on OOM
diff --git a/includes/media/XCF.php b/includes/media/XCF.php
new file mode 100644 (file)
index 0000000..e2e7031
--- /dev/null
@@ -0,0 +1,93 @@
+<?php
+/**
+ * Handler for Microsoft's bitmap format
+ *
+ * @file
+ * @ingroup Media
+ */
+
+/**
+ * Handler for Microsoft's bitmap format; getimagesize() doesn't
+ * support these files
+ *
+ * @ingroup Media
+ */
+class XCFHandler extends BitmapHandler {
+
+       /**
+        * Render files as PNG
+        *
+        * @param $ext
+        * @param $mime
+        * @param $params
+        * @return array
+        */
+       function getThumbType( $ext, $mime, $params = null ) {
+               return array( 'png', 'image/png' );
+       }
+
+       /**
+        * Get width and height from the bmp header.
+        *
+        * @param $image
+        * @param $filename
+        * @return array
+        */
+       function getImageSize( $image, $filename ) {
+               return self::getXCFMetaData( $filename );
+       }
+
+       static function getXCFMetaData( $filename ) {
+               global $wgImageMagickIdentifyCommand;
+
+               $md = false;
+               $cmd = wfEscapeShellArg( $wgImageMagickIdentifyCommand ) . ' -verbose ' . wfEscapeShellArg( $filename );
+               wfDebug( __METHOD__ . ": Running $cmd \n" );
+               $retval = '';
+               $return = wfShellExec( $cmd, $retval );
+
+               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" );
+
+                       /* 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];
+                                       }
+                               }
+                       /* } */
+
+                       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;
+       }
+
+       /**
+        * Must use "im" for XCF
+        *
+        * @return string
+        */
+       protected static function getScalerType( $dstPath, $checkDstPath = true ) {
+               return "im";
+       }
+}