'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
$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';
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' ) );
--- /dev/null
+<?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";
+ }
+}