* 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.
This commit is contained in:
parent
f8f0a71beb
commit
d93ece3527
4 changed files with 103 additions and 2 deletions
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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' ) );
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
93
includes/media/XCF.php
Normal file
93
includes/media/XCF.php
Normal file
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue