From: Brion Vibber Date: Mon, 13 Oct 2008 21:50:16 +0000 (+0000) Subject: Quick hack: add $wgMaxAnimatedGifArea so we don't try to render animated thumbs for... X-Git-Tag: 1.31.0-rc.0~44746 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/rappel_supprimer.php?a=commitdiff_plain;h=7a6f69f500dd1dce26d8cdd328b4c212b10a3e1c;p=lhc%2Fweb%2Fwiklou.git Quick hack: add $wgMaxAnimatedGifArea so we don't try to render animated thumbs for huge animated GIFs. 'Tugra Mahmuds II Big Size.gif' on Commons otherwise seems to eat as much CPU and memory as you can throw at it (1,876 × 1,500 pixel, file size: 4.36 MB, MIME type: image/gif) --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 0a2b817cc5..123e23abed 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1956,6 +1956,13 @@ $wgSVGMaxSize = 2048; * 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. diff --git a/includes/media/Bitmap.php b/includes/media/Bitmap.php index 39d70a6594..9dbc40d833 100644 --- a/includes/media/Bitmap.php +++ b/includes/media/Bitmap.php @@ -44,6 +44,7 @@ class BitmapHandler extends ImageHandler { global $wgUseImageMagick, $wgImageMagickConvertCommand; global $wgCustomConvertCommand; global $wgSharpenParameter, $wgSharpenReductionThreshold; + global $wgMaxAnimatedGifArea; if ( !$this->normaliseParams( $image, $params ) ) { return new TransformParameterError( $params ); @@ -77,6 +78,7 @@ class BitmapHandler extends ImageHandler { } else { $scaler = 'client'; } + wfDebug( __METHOD__.": scaler $scaler\n" ); if ( $scaler == 'client' ) { # Client-side image scaling, use the source URL @@ -85,18 +87,22 @@ class BitmapHandler extends ImageHandler { } 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 @@ -105,8 +111,15 @@ class BitmapHandler extends ImageHandler { } } 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 @@ -118,9 +131,8 @@ class BitmapHandler extends ImageHandler { $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.