Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -1957,6 +1957,13 @@ |
1958 | 1958 | */ |
1959 | 1959 | $wgMaxImageArea = 1.25e7; |
1960 | 1960 | /** |
| 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 | +/** |
1961 | 1968 | * If rendered thumbnail files are older than this timestamp, they |
1962 | 1969 | * will be rerendered on demand as if the file didn't already exist. |
1963 | 1970 | * Update if there is some need to force thumbs and SVG rasterizations |
Index: trunk/phase3/includes/media/Bitmap.php |
— | — | @@ -44,6 +44,7 @@ |
45 | 45 | global $wgUseImageMagick, $wgImageMagickConvertCommand; |
46 | 46 | global $wgCustomConvertCommand; |
47 | 47 | global $wgSharpenParameter, $wgSharpenReductionThreshold; |
| 48 | + global $wgMaxAnimatedGifArea; |
48 | 49 | |
49 | 50 | if ( !$this->normaliseParams( $image, $params ) ) { |
50 | 51 | return new TransformParameterError( $params ); |
— | — | @@ -77,6 +78,7 @@ |
78 | 79 | } else { |
79 | 80 | $scaler = 'client'; |
80 | 81 | } |
| 82 | + wfDebug( __METHOD__.": scaler $scaler\n" ); |
81 | 83 | |
82 | 84 | if ( $scaler == 'client' ) { |
83 | 85 | # Client-side image scaling, use the source URL |
— | — | @@ -85,18 +87,22 @@ |
86 | 88 | } |
87 | 89 | |
88 | 90 | if ( $flags & self::TRANSFORM_LATER ) { |
| 91 | + wfDebug( __METHOD__.": Transforming later per flags.\n" ); |
89 | 92 | return new ThumbnailImage( $image, $dstUrl, $clientWidth, $clientHeight, $dstPath ); |
90 | 93 | } |
91 | 94 | |
92 | 95 | 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" ); |
94 | 97 | return new ThumbnailImage( $image, $image->getURL(), $clientWidth, $clientHeight, $srcPath ); |
95 | 98 | } |
96 | 99 | |
97 | 100 | if ( $scaler == 'im' ) { |
98 | 101 | # use ImageMagick |
99 | 102 | |
| 103 | + $quality = ''; |
100 | 104 | $sharpen = ''; |
| 105 | + $frame = ''; |
| 106 | + $animation = ''; |
101 | 107 | if ( $mimeType == 'image/jpeg' ) { |
102 | 108 | $quality = "-quality 80"; // 80% |
103 | 109 | # Sharpening, see bug 6193 |
— | — | @@ -105,8 +111,15 @@ |
106 | 112 | } |
107 | 113 | } elseif ( $mimeType == 'image/png' ) { |
108 | 114 | $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 | + } |
111 | 124 | } |
112 | 125 | |
113 | 126 | # Specify white background color, will be used for transparent images |
— | — | @@ -118,9 +131,8 @@ |
119 | 132 | |
120 | 133 | $cmd = wfEscapeShellArg($wgImageMagickConvertCommand) . |
121 | 134 | " {$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 . |
125 | 137 | // For the -resize option a "!" is needed to force exact size, |
126 | 138 | // or ImageMagick may decide your ratio is wrong and slice off |
127 | 139 | // a pixel. |