r42058 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42057‎ | r42058 | r42059 >
Date:21:50, 13 October 2008
Author:brion
Status:old (Comments)
Tags:
Comment:
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)
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/media/Bitmap.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DefaultSettings.php
@@ -1957,6 +1957,13 @@
19581958 */
19591959 $wgMaxImageArea = 1.25e7;
19601960 /**
 1961+ * Force thumbnailing of animated GIFs above this size to a single
 1962+ * frame instead of an animated thumbnail. ImageMagick seems to
 1963+ * get real unhappy and doesn't play well with resource limits. :P
 1964+ * Defaulting to 1 megapixel (1000x1000)
 1965+ */
 1966+$wgMaxAnimatedGifArea = 1.0e6;
 1967+/**
19611968 * If rendered thumbnail files are older than this timestamp, they
19621969 * will be rerendered on demand as if the file didn't already exist.
19631970 * Update if there is some need to force thumbs and SVG rasterizations
Index: trunk/phase3/includes/media/Bitmap.php
@@ -44,6 +44,7 @@
4545 global $wgUseImageMagick, $wgImageMagickConvertCommand;
4646 global $wgCustomConvertCommand;
4747 global $wgSharpenParameter, $wgSharpenReductionThreshold;
 48+ global $wgMaxAnimatedGifArea;
4849
4950 if ( !$this->normaliseParams( $image, $params ) ) {
5051 return new TransformParameterError( $params );
@@ -77,6 +78,7 @@
7879 } else {
7980 $scaler = 'client';
8081 }
 82+ wfDebug( __METHOD__.": scaler $scaler\n" );
8183
8284 if ( $scaler == 'client' ) {
8385 # Client-side image scaling, use the source URL
@@ -85,18 +87,22 @@
8688 }
8789
8890 if ( $flags & self::TRANSFORM_LATER ) {
 91+ wfDebug( __METHOD__.": Transforming later per flags.\n" );
8992 return new ThumbnailImage( $image, $dstUrl, $clientWidth, $clientHeight, $dstPath );
9093 }
9194
9295 if ( !wfMkdirParents( dirname( $dstPath ) ) ) {
93 - wfDebug( "Unable to create thumbnail destination directory, falling back to client scaling\n" );
 96+ wfDebug( __METHOD__.": Unable to create thumbnail destination directory, falling back to client scaling\n" );
9497 return new ThumbnailImage( $image, $image->getURL(), $clientWidth, $clientHeight, $srcPath );
9598 }
9699
97100 if ( $scaler == 'im' ) {
98101 # use ImageMagick
99102
 103+ $quality = '';
100104 $sharpen = '';
 105+ $frame = '';
 106+ $animation = '';
101107 if ( $mimeType == 'image/jpeg' ) {
102108 $quality = "-quality 80"; // 80%
103109 # Sharpening, see bug 6193
@@ -105,8 +111,15 @@
106112 }
107113 } elseif ( $mimeType == 'image/png' ) {
108114 $quality = "-quality 95"; // zlib 9, adaptive filtering
109 - } else {
110 - $quality = ''; // default
 115+ } elseif( $mimeType == 'image/gif' ) {
 116+ if( $srcWidth * $srcHeight > $wgMaxAnimatedGifArea ) {
 117+ // Extract initial frame only; we're so big it'll
 118+ // be a total drag. :P
 119+ $frame = '[0]';
 120+ } else {
 121+ // Coalesce is needed to scale animated GIFs properly (bug 1017).
 122+ $animation = ' -coalesce ';
 123+ }
111124 }
112125
113126 # Specify white background color, will be used for transparent images
@@ -118,9 +131,8 @@
119132
120133 $cmd = wfEscapeShellArg($wgImageMagickConvertCommand) .
121134 " {$quality} -background white -size {$physicalWidth} ".
122 - wfEscapeShellArg($srcPath) .
123 - // Coalesce is needed to scale animated GIFs properly (bug 1017).
124 - ' -coalesce ' .
 135+ wfEscapeShellArg($srcPath . $frame) .
 136+ $animation .
125137 // For the -resize option a "!" is needed to force exact size,
126138 // or ImageMagick may decide your ratio is wrong and slice off
127139 // a pixel.

Comments

#Comment by Brion VIBBER (talk | contribs)   22:06, 13 October 2008

put this one live for now, sigh... Commons:Image_talk:Tugra_Mahmuds_II_Big_Size.gif

Status & tagging log