From 7a6f69f500dd1dce26d8cdd328b4c212b10a3e1c Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 13 Oct 2008 21:50:16 +0000 Subject: [PATCH] =?utf8?q?Quick=20hack:=20add=20$wgMaxAnimatedGifArea=20so?= =?utf8?q?=20we=20don't=20try=20to=20render=20animated=20thumbs=20for=20hu?= =?utf8?q?ge=20animated=20GIFs.=20'Tugra=20Mahmuds=20II=20Big=20Size.gif'?= =?utf8?q?=20on=20Commons=20otherwise=20seems=20to=20eat=20as=20much=20CPU?= =?utf8?q?=20and=20memory=20as=20you=20can=20throw=20at=20it=20(1,876=20?= =?utf8?q?=C3=97=201,500=20pixel,=20file=20size:=204.36=20MB,=20MIME=20typ?= =?utf8?q?e:=20image/gif)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- includes/DefaultSettings.php | 7 +++++++ includes/media/Bitmap.php | 24 ++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) 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. -- 2.20.1