* 12.5 million pixels or 3500x3500
*/
$wgMaxImageArea = 1.25e7;
+/**
+ * Force thumbnailing of animated GIFs above this size to a single
+ * frame instead of an animated thumbnail. ImageMagick seems to
+ * get real unhappy and doesn't play well with resource limits. :P
+ * Defaulting to 1 megapixel (1000x1000)
+ */
+$wgMaxAnimatedGifArea = 1.0e6;
/**
* If rendered thumbnail files are older than this timestamp, they
* will be rerendered on demand as if the file didn't already exist.
global $wgUseImageMagick, $wgImageMagickConvertCommand;
global $wgCustomConvertCommand;
global $wgSharpenParameter, $wgSharpenReductionThreshold;
+ global $wgMaxAnimatedGifArea;
if ( !$this->normaliseParams( $image, $params ) ) {
return new TransformParameterError( $params );
} else {
$scaler = 'client';
}
+ wfDebug( __METHOD__.": scaler $scaler\n" );
if ( $scaler == 'client' ) {
# Client-side image scaling, use the source URL
}
if ( $flags & self::TRANSFORM_LATER ) {
+ wfDebug( __METHOD__.": Transforming later per flags.\n" );
return new ThumbnailImage( $image, $dstUrl, $clientWidth, $clientHeight, $dstPath );
}
if ( !wfMkdirParents( dirname( $dstPath ) ) ) {
- wfDebug( "Unable to create thumbnail destination directory, falling back to client scaling\n" );
+ wfDebug( __METHOD__.": Unable to create thumbnail destination directory, falling back to client scaling\n" );
return new ThumbnailImage( $image, $image->getURL(), $clientWidth, $clientHeight, $srcPath );
}
if ( $scaler == 'im' ) {
# use ImageMagick
+ $quality = '';
$sharpen = '';
+ $frame = '';
+ $animation = '';
if ( $mimeType == 'image/jpeg' ) {
$quality = "-quality 80"; // 80%
# Sharpening, see bug 6193
}
} elseif ( $mimeType == 'image/png' ) {
$quality = "-quality 95"; // zlib 9, adaptive filtering
- } else {
- $quality = ''; // default
+ } elseif( $mimeType == 'image/gif' ) {
+ if( $srcWidth * $srcHeight > $wgMaxAnimatedGifArea ) {
+ // Extract initial frame only; we're so big it'll
+ // be a total drag. :P
+ $frame = '[0]';
+ } else {
+ // Coalesce is needed to scale animated GIFs properly (bug 1017).
+ $animation = ' -coalesce ';
+ }
}
# Specify white background color, will be used for transparent images
$cmd = wfEscapeShellArg($wgImageMagickConvertCommand) .
" {$quality} -background white -size {$physicalWidth} ".
- wfEscapeShellArg($srcPath) .
- // Coalesce is needed to scale animated GIFs properly (bug 1017).
- ' -coalesce ' .
+ wfEscapeShellArg($srcPath . $frame) .
+ $animation .
// For the -resize option a "!" is needed to force exact size,
// or ImageMagick may decide your ratio is wrong and slice off
// a pixel.