From d93ece35276f711f26d680df207155e62b7946ac Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Tue, 27 Dec 2011 00:46:44 +0000 Subject: [PATCH] * First simple XCF thumbnailing. Convert from ImageMagick has buggy 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 | 3 ++ includes/filerepo/file/File.php | 7 ++- includes/media/Bitmap.php | 2 + includes/media/XCF.php | 93 +++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 includes/media/XCF.php diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index bd12a040c7..0f6dd0eaec 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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'; diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 04fa2f463a..7cb9e27d9e 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -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' ) ); diff --git a/includes/media/Bitmap.php b/includes/media/Bitmap.php index 0a4c55f3c6..878ad58fb9 100644 --- a/includes/media/Bitmap.php +++ b/includes/media/Bitmap.php @@ -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 index 0000000000..e2e7031b06 --- /dev/null +++ b/includes/media/XCF.php @@ -0,0 +1,93 @@ + $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"; + } +} -- 2.20.1