Index: trunk/phase3/includes/media/Bitmap.php |
— | — | @@ -30,7 +30,7 @@ |
31 | 31 | $params['physicalWidth'] = $srcWidth; |
32 | 32 | $params['physicalHeight'] = $srcHeight; |
33 | 33 | # Skip scaling limit checks if no scaling is required |
34 | | - if( !$image->mustRender() ) |
| 34 | + if ( !$image->mustRender() ) |
35 | 35 | return true; |
36 | 36 | } |
37 | 37 | |
— | — | @@ -46,8 +46,8 @@ |
47 | 47 | |
48 | 48 | return true; |
49 | 49 | } |
50 | | - |
51 | | - |
| 50 | + |
| 51 | + |
52 | 52 | // Function that returns the number of pixels to be thumbnailed. |
53 | 53 | // Intended for animated GIFs to multiply by the number of frames. |
54 | 54 | function getImageArea( $image, $width, $height ) { |
— | — | @@ -71,7 +71,7 @@ |
72 | 72 | 'clientWidth' => $params['width'], |
73 | 73 | 'clientHeight' => $params['height'], |
74 | 74 | # Comment as will be added to the EXIF of the thumbnail |
75 | | - 'comment' => isset( $params['descriptionUrl'] ) ? |
| 75 | + 'comment' => isset( $params['descriptionUrl'] ) ? |
76 | 76 | "File source: {$params['descriptionUrl']}" : '', |
77 | 77 | # Properties of the original image |
78 | 78 | 'srcWidth' => $image->getWidth(), |
— | — | @@ -83,10 +83,10 @@ |
84 | 84 | |
85 | 85 | wfDebug( __METHOD__ . ": creating {$scalerParams['physicalSize']} thumbnail at $dstPath\n" ); |
86 | 86 | |
87 | | - if ( !$image->mustRender() && |
| 87 | + if ( !$image->mustRender() && |
88 | 88 | $scalerParams['physicalWidth'] == $scalerParams['srcWidth'] |
89 | 89 | && $scalerParams['physicalHeight'] == $scalerParams['srcHeight'] ) { |
90 | | - |
| 90 | + |
91 | 91 | # normaliseParams (or the user) wants us to return the unscaled image |
92 | 92 | wfDebug( __METHOD__ . ": returning unscaled image\n" ); |
93 | 93 | return $this->getClientScalingThumbnailImage( $image, $scalerParams ); |
— | — | @@ -96,7 +96,7 @@ |
97 | 97 | if ( !$dstPath ) { |
98 | 98 | # No output path available, client side scaling only |
99 | 99 | $scaler = 'client'; |
100 | | - } elseif( !$wgUseImageResize ) { |
| 100 | + } elseif ( !$wgUseImageResize ) { |
101 | 101 | $scaler = 'client'; |
102 | 102 | } elseif ( $wgUseImageMagick ) { |
103 | 103 | $scaler = 'im'; |
— | — | @@ -117,13 +117,13 @@ |
118 | 118 | |
119 | 119 | if ( $flags & self::TRANSFORM_LATER ) { |
120 | 120 | wfDebug( __METHOD__ . ": Transforming later per flags.\n" ); |
121 | | - return new ThumbnailImage( $image, $dstUrl, $scalerParams['clientWidth'], |
| 121 | + return new ThumbnailImage( $image, $dstUrl, $scalerParams['clientWidth'], |
122 | 122 | $scalerParams['clientHeight'], $dstPath ); |
123 | 123 | } |
124 | 124 | |
125 | 125 | # Try to make a target path for the thumbnail |
126 | 126 | if ( !wfMkdirParents( dirname( $dstPath ) ) ) { |
127 | | - wfDebug( __METHOD__.": Unable to create thumbnail destination directory, falling back to client scaling\n" ); |
| 127 | + wfDebug( __METHOD__ . ": Unable to create thumbnail destination directory, falling back to client scaling\n" ); |
128 | 128 | return $this->getClientScalingThumbnailImage( $image, $scalerParams ); |
129 | 129 | } |
130 | 130 | |
— | — | @@ -139,7 +139,7 @@ |
140 | 140 | $err = $this->transformGd( $image, $scalerParams ); |
141 | 141 | break; |
142 | 142 | } |
143 | | - |
| 143 | + |
144 | 144 | # Remove the file if a zero-byte thumbnail was created, or if there was an error |
145 | 145 | $removed = $this->removeBadFile( $dstPath, (bool)$err ); |
146 | 146 | if ( $err ) { |
— | — | @@ -147,152 +147,152 @@ |
148 | 148 | return $err; |
149 | 149 | } elseif ( $removed ) { |
150 | 150 | # Thumbnail was zero-byte and had to be removed |
151 | | - return new MediaTransformError( 'thumbnail_error', |
| 151 | + return new MediaTransformError( 'thumbnail_error', |
152 | 152 | $scalerParams['clientWidth'], $scalerParams['clientHeight'] ); |
153 | 153 | } else { |
154 | | - return new ThumbnailImage( $image, $dstUrl, $scalerParams['clientWidth'], |
| 154 | + return new ThumbnailImage( $image, $dstUrl, $scalerParams['clientWidth'], |
155 | 155 | $scalerParams['clientHeight'], $dstPath ); |
156 | 156 | } |
157 | 157 | } |
158 | | - |
| 158 | + |
159 | 159 | /** |
160 | 160 | * Get a ThumbnailImage that respresents an image that will be scaled |
161 | 161 | * client side |
162 | | - * |
| 162 | + * |
163 | 163 | * @param $image File File associated with this thumbnail |
164 | 164 | * @param $params array Array with scaler params |
165 | 165 | * @return ThumbnailImage |
166 | 166 | */ |
167 | 167 | protected function getClientScalingThumbnailImage( $image, $params ) { |
168 | | - return new ThumbnailImage( $image, $image->getURL(), |
| 168 | + return new ThumbnailImage( $image, $image->getURL(), |
169 | 169 | $params['clientWidth'], $params['clientHeight'], $params['srcPath'] ); |
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
173 | 173 | * Transform an image using ImageMagick |
174 | | - * |
| 174 | + * |
175 | 175 | * @param $image File File associated with this thumbnail |
176 | 176 | * @param $params array Array with scaler params |
177 | | - * |
| 177 | + * |
178 | 178 | * @return MediaTransformError Error object if error occured, false (=no error) otherwise |
179 | 179 | */ |
180 | 180 | protected function transformImageMagick( $image, $params ) { |
181 | | - # use ImageMagick |
182 | | - global $wgSharpenReductionThreshold, $wgSharpenParameter, |
183 | | - $wgMaxAnimatedGifArea, |
184 | | - $wgImageMagickTempDir, $wgImageMagickConvertCommand; |
| 181 | + # use ImageMagick |
| 182 | + global $wgSharpenReductionThreshold, $wgSharpenParameter, |
| 183 | + $wgMaxAnimatedGifArea, |
| 184 | + $wgImageMagickTempDir, $wgImageMagickConvertCommand; |
185 | 185 | |
186 | | - $quality = ''; |
187 | | - $sharpen = ''; |
188 | | - $scene = false; |
189 | | - $animation_pre = ''; |
190 | | - $animation_post = ''; |
191 | | - $decoderHint = ''; |
192 | | - if ( $params['mimeType'] == 'image/jpeg' ) { |
193 | | - $quality = "-quality 80"; // 80% |
194 | | - # Sharpening, see bug 6193 |
195 | | - if ( ( $params['physicalWidth'] + $params['physicalHeight'] ) |
196 | | - / ( $params['srcWidth'] + $params['srcHeight'] ) |
197 | | - < $wgSharpenReductionThreshold ) { |
198 | | - $sharpen = "-sharpen " . wfEscapeShellArg( $wgSharpenParameter ); |
199 | | - } |
200 | | - // JPEG decoder hint to reduce memory, available since IM 6.5.6-2 |
201 | | - $decoderHint = "-define jpeg:size={$params['physicalSize']}"; |
202 | | - |
203 | | - } elseif ( $params['mimeType'] == 'image/png' ) { |
204 | | - $quality = "-quality 95"; // zlib 9, adaptive filtering |
205 | | - |
206 | | - } elseif ( $params['mimeType'] == 'image/gif' ) { |
207 | | - if ( $this->getImageArea( $image, $params['srcWidth'], |
208 | | - $params['srcHeight'] ) > $wgMaxAnimatedGifArea ) { |
209 | | - // Extract initial frame only; we're so big it'll |
210 | | - // be a total drag. :P |
211 | | - $scene = 0; |
212 | | - |
213 | | - } elseif( $this->isAnimatedImage( $image ) ) { |
214 | | - // Coalesce is needed to scale animated GIFs properly (bug 1017). |
215 | | - $animation_pre = '-coalesce'; |
216 | | - // We optimize the output, but -optimize is broken, |
217 | | - // use optimizeTransparency instead (bug 11822) |
218 | | - if( version_compare( $this->getMagickVersion(), "6.3.5" ) >= 0 ) { |
219 | | - $animation_post = '-fuzz 5% -layers optimizeTransparency +map'; |
220 | | - } |
221 | | - } |
| 186 | + $quality = ''; |
| 187 | + $sharpen = ''; |
| 188 | + $scene = false; |
| 189 | + $animation_pre = ''; |
| 190 | + $animation_post = ''; |
| 191 | + $decoderHint = ''; |
| 192 | + if ( $params['mimeType'] == 'image/jpeg' ) { |
| 193 | + $quality = "-quality 80"; // 80% |
| 194 | + # Sharpening, see bug 6193 |
| 195 | + if ( ( $params['physicalWidth'] + $params['physicalHeight'] ) |
| 196 | + / ( $params['srcWidth'] + $params['srcHeight'] ) |
| 197 | + < $wgSharpenReductionThreshold ) { |
| 198 | + $sharpen = "-sharpen " . wfEscapeShellArg( $wgSharpenParameter ); |
222 | 199 | } |
| 200 | + // JPEG decoder hint to reduce memory, available since IM 6.5.6-2 |
| 201 | + $decoderHint = "-define jpeg:size={$params['physicalSize']}"; |
223 | 202 | |
224 | | - // Use one thread only, to avoid deadlock bugs on OOM |
225 | | - $env = array( 'OMP_NUM_THREADS' => 1 ); |
226 | | - if ( strval( $wgImageMagickTempDir ) !== '' ) { |
227 | | - $env['MAGICK_TMPDIR'] = $wgImageMagickTempDir; |
| 203 | + } elseif ( $params['mimeType'] == 'image/png' ) { |
| 204 | + $quality = "-quality 95"; // zlib 9, adaptive filtering |
| 205 | + |
| 206 | + } elseif ( $params['mimeType'] == 'image/gif' ) { |
| 207 | + if ( $this->getImageArea( $image, $params['srcWidth'], |
| 208 | + $params['srcHeight'] ) > $wgMaxAnimatedGifArea ) { |
| 209 | + // Extract initial frame only; we're so big it'll |
| 210 | + // be a total drag. :P |
| 211 | + $scene = 0; |
| 212 | + |
| 213 | + } elseif ( $this->isAnimatedImage( $image ) ) { |
| 214 | + // Coalesce is needed to scale animated GIFs properly (bug 1017). |
| 215 | + $animation_pre = '-coalesce'; |
| 216 | + // We optimize the output, but -optimize is broken, |
| 217 | + // use optimizeTransparency instead (bug 11822) |
| 218 | + if ( version_compare( $this->getMagickVersion(), "6.3.5" ) >= 0 ) { |
| 219 | + $animation_post = '-fuzz 5% -layers optimizeTransparency +map'; |
| 220 | + } |
228 | 221 | } |
| 222 | + } |
229 | 223 | |
230 | | - $cmd = |
231 | | - wfEscapeShellArg( $wgImageMagickConvertCommand ) . |
232 | | - // Specify white background color, will be used for transparent images |
233 | | - // in Internet Explorer/Windows instead of default black. |
234 | | - " {$quality} -background white". |
235 | | - " {$decoderHint} " . |
236 | | - wfEscapeShellArg( $this->escapeMagickInput( $params['srcPath'], $scene ) ) . |
237 | | - " {$animation_pre}" . |
238 | | - // For the -thumbnail option a "!" is needed to force exact size, |
239 | | - // or ImageMagick may decide your ratio is wrong and slice off |
240 | | - // a pixel. |
241 | | - " -thumbnail " . wfEscapeShellArg( "{$params['physicalSize']}!" ) . |
242 | | - // Add the source url as a comment to the thumb. |
243 | | - " -set comment " . wfEscapeShellArg( $this->escapeMagickProperty( $params['comment'] ) ) . |
244 | | - " -depth 8 $sharpen" . |
245 | | - " {$animation_post} " . |
246 | | - wfEscapeShellArg( $this->escapeMagickOutput( $params['dstPath'] ) ) . " 2>&1"; |
| 224 | + // Use one thread only, to avoid deadlock bugs on OOM |
| 225 | + $env = array( 'OMP_NUM_THREADS' => 1 ); |
| 226 | + if ( strval( $wgImageMagickTempDir ) !== '' ) { |
| 227 | + $env['MAGICK_TMPDIR'] = $wgImageMagickTempDir; |
| 228 | + } |
247 | 229 | |
248 | | - wfDebug( __METHOD__.": running ImageMagick: $cmd\n" ); |
249 | | - wfProfileIn( 'convert' ); |
250 | | - $retval = 0; |
251 | | - $err = wfShellExec( $cmd, $retval, $env ); |
252 | | - wfProfileOut( 'convert' ); |
253 | | - |
254 | | - if ( $retval !== 0 ) { |
255 | | - $this->logErrorForExternalProcess( $retval, $err, $cmd ); |
256 | | - return $this->getMediaTransformError( $params, $err ); |
257 | | - } |
258 | | - |
259 | | - return false; # No error |
| 230 | + $cmd = |
| 231 | + wfEscapeShellArg( $wgImageMagickConvertCommand ) . |
| 232 | + // Specify white background color, will be used for transparent images |
| 233 | + // in Internet Explorer/Windows instead of default black. |
| 234 | + " {$quality} -background white" . |
| 235 | + " {$decoderHint} " . |
| 236 | + wfEscapeShellArg( $this->escapeMagickInput( $params['srcPath'], $scene ) ) . |
| 237 | + " {$animation_pre}" . |
| 238 | + // For the -thumbnail option a "!" is needed to force exact size, |
| 239 | + // or ImageMagick may decide your ratio is wrong and slice off |
| 240 | + // a pixel. |
| 241 | + " -thumbnail " . wfEscapeShellArg( "{$params['physicalSize']}!" ) . |
| 242 | + // Add the source url as a comment to the thumb. |
| 243 | + " -set comment " . wfEscapeShellArg( $this->escapeMagickProperty( $params['comment'] ) ) . |
| 244 | + " -depth 8 $sharpen" . |
| 245 | + " {$animation_post} " . |
| 246 | + wfEscapeShellArg( $this->escapeMagickOutput( $params['dstPath'] ) ) . " 2>&1"; |
| 247 | + |
| 248 | + wfDebug( __METHOD__ . ": running ImageMagick: $cmd\n" ); |
| 249 | + wfProfileIn( 'convert' ); |
| 250 | + $retval = 0; |
| 251 | + $err = wfShellExec( $cmd, $retval, $env ); |
| 252 | + wfProfileOut( 'convert' ); |
| 253 | + |
| 254 | + if ( $retval !== 0 ) { |
| 255 | + $this->logErrorForExternalProcess( $retval, $err, $cmd ); |
| 256 | + return $this->getMediaTransformError( $params, $err ); |
| 257 | + } |
| 258 | + |
| 259 | + return false; # No error |
260 | 260 | } |
261 | | - |
| 261 | + |
262 | 262 | /** |
263 | 263 | * Transform an image using a custom command |
264 | | - * |
| 264 | + * |
265 | 265 | * @param $image File File associated with this thumbnail |
266 | 266 | * @param $params array Array with scaler params |
267 | | - * |
| 267 | + * |
268 | 268 | * @return MediaTransformError Error object if error occured, false (=no error) otherwise |
269 | 269 | */ |
270 | 270 | protected function transformCustom( $image, $params ) { |
271 | | - # Use a custom convert command |
272 | | - global $wgCustomConvertCommand; |
273 | | - |
274 | | - # Variables: %s %d %w %h |
275 | | - $src = wfEscapeShellArg( $params['srcPath'] ); |
276 | | - $dst = wfEscapeShellArg( $params['dstPath'] ); |
277 | | - $cmd = $wgCustomConvertCommand; |
278 | | - $cmd = str_replace( '%s', $src, str_replace( '%d', $dst, $cmd ) ); # Filenames |
279 | | - $cmd = str_replace( '%h', $params['physicalHeight'], |
280 | | - str_replace( '%w', $params['physicalWidth'], $cmd ) ); # Size |
281 | | - wfDebug( __METHOD__.": Running custom convert command $cmd\n" ); |
282 | | - wfProfileIn( 'convert' ); |
283 | | - $retval = 0; |
284 | | - $err = wfShellExec( $cmd, $retval ); |
285 | | - wfProfileOut( 'convert' ); |
286 | | - |
287 | | - if ( $retval !== 0 ) { |
288 | | - $this->logErrorForExternalProcess( $retval, $err, $cmd ); |
289 | | - return $this->getMediaTransformError( $params, $err ); |
290 | | - } |
291 | | - return false; # No error |
| 271 | + # Use a custom convert command |
| 272 | + global $wgCustomConvertCommand; |
| 273 | + |
| 274 | + # Variables: %s %d %w %h |
| 275 | + $src = wfEscapeShellArg( $params['srcPath'] ); |
| 276 | + $dst = wfEscapeShellArg( $params['dstPath'] ); |
| 277 | + $cmd = $wgCustomConvertCommand; |
| 278 | + $cmd = str_replace( '%s', $src, str_replace( '%d', $dst, $cmd ) ); # Filenames |
| 279 | + $cmd = str_replace( '%h', $params['physicalHeight'], |
| 280 | + str_replace( '%w', $params['physicalWidth'], $cmd ) ); # Size |
| 281 | + wfDebug( __METHOD__ . ": Running custom convert command $cmd\n" ); |
| 282 | + wfProfileIn( 'convert' ); |
| 283 | + $retval = 0; |
| 284 | + $err = wfShellExec( $cmd, $retval ); |
| 285 | + wfProfileOut( 'convert' ); |
| 286 | + |
| 287 | + if ( $retval !== 0 ) { |
| 288 | + $this->logErrorForExternalProcess( $retval, $err, $cmd ); |
| 289 | + return $this->getMediaTransformError( $params, $err ); |
| 290 | + } |
| 291 | + return false; # No error |
292 | 292 | } |
293 | | - |
| 293 | + |
294 | 294 | /** |
295 | 295 | * Log an error that occured in an external process |
296 | | - * |
| 296 | + * |
297 | 297 | * @param $retval int |
298 | 298 | * @param $err int |
299 | 299 | * @param $cmd string |
— | — | @@ -303,87 +303,87 @@ |
304 | 304 | wfHostname(), $retval, trim( $err ), $cmd ) ); |
305 | 305 | } |
306 | 306 | /** |
307 | | - * |
| 307 | + * |
308 | 308 | */ |
309 | 309 | protected function getMediaTransformError( $params, $errMsg ) { |
310 | | - return new MediaTransformError( 'thumbnail_error', $params['clientWidth'], |
| 310 | + return new MediaTransformError( 'thumbnail_error', $params['clientWidth'], |
311 | 311 | $params['clientHeight'], $errMsg ); |
312 | 312 | } |
313 | | - |
| 313 | + |
314 | 314 | /** |
315 | 315 | * Transform an image using the built in GD library |
316 | | - * |
| 316 | + * |
317 | 317 | * @param $image File File associated with this thumbnail |
318 | 318 | * @param $params array Array with scaler params |
319 | | - * |
| 319 | + * |
320 | 320 | * @return MediaTransformError Error object if error occured, false (=no error) otherwise |
321 | 321 | */ |
322 | 322 | protected function transformGd( $image, $params ) { |
323 | | - # Use PHP's builtin GD library functions. |
324 | | - # |
325 | | - # First find out what kind of file this is, and select the correct |
326 | | - # input routine for this. |
| 323 | + # Use PHP's builtin GD library functions. |
| 324 | + # |
| 325 | + # First find out what kind of file this is, and select the correct |
| 326 | + # input routine for this. |
327 | 327 | |
328 | | - $typemap = array( |
329 | | - 'image/gif' => array( 'imagecreatefromgif', 'palette', 'imagegif' ), |
330 | | - 'image/jpeg' => array( 'imagecreatefromjpeg', 'truecolor', array( __CLASS__, 'imageJpegWrapper' ) ), |
331 | | - 'image/png' => array( 'imagecreatefrompng', 'bits', 'imagepng' ), |
332 | | - 'image/vnd.wap.wbmp' => array( 'imagecreatefromwbmp', 'palette', 'imagewbmp' ), |
333 | | - 'image/xbm' => array( 'imagecreatefromxbm', 'palette', 'imagexbm' ), |
334 | | - ); |
335 | | - if( !isset( $typemap[$params['mimeType']] ) ) { |
336 | | - $err = 'Image type not supported'; |
337 | | - wfDebug( "$err\n" ); |
338 | | - $errMsg = wfMsg ( 'thumbnail_image-type' ); |
339 | | - return $this->getMediaTransformError( $params, $errMsg ); |
340 | | - } |
341 | | - list( $loader, $colorStyle, $saveType ) = $typemap[$params['mimeType']]; |
| 328 | + $typemap = array( |
| 329 | + 'image/gif' => array( 'imagecreatefromgif', 'palette', 'imagegif' ), |
| 330 | + 'image/jpeg' => array( 'imagecreatefromjpeg', 'truecolor', array( __CLASS__, 'imageJpegWrapper' ) ), |
| 331 | + 'image/png' => array( 'imagecreatefrompng', 'bits', 'imagepng' ), |
| 332 | + 'image/vnd.wap.wbmp' => array( 'imagecreatefromwbmp', 'palette', 'imagewbmp' ), |
| 333 | + 'image/xbm' => array( 'imagecreatefromxbm', 'palette', 'imagexbm' ), |
| 334 | + ); |
| 335 | + if ( !isset( $typemap[$params['mimeType']] ) ) { |
| 336 | + $err = 'Image type not supported'; |
| 337 | + wfDebug( "$err\n" ); |
| 338 | + $errMsg = wfMsg ( 'thumbnail_image-type' ); |
| 339 | + return $this->getMediaTransformError( $params, $errMsg ); |
| 340 | + } |
| 341 | + list( $loader, $colorStyle, $saveType ) = $typemap[$params['mimeType']]; |
342 | 342 | |
343 | | - if( !function_exists( $loader ) ) { |
344 | | - $err = "Incomplete GD library configuration: missing function $loader"; |
345 | | - wfDebug( "$err\n" ); |
346 | | - $errMsg = wfMsg ( 'thumbnail_gd-library', $loader ); |
347 | | - return $this->getMediaTransformError( $params, $errMsg ); |
348 | | - } |
| 343 | + if ( !function_exists( $loader ) ) { |
| 344 | + $err = "Incomplete GD library configuration: missing function $loader"; |
| 345 | + wfDebug( "$err\n" ); |
| 346 | + $errMsg = wfMsg ( 'thumbnail_gd-library', $loader ); |
| 347 | + return $this->getMediaTransformError( $params, $errMsg ); |
| 348 | + } |
349 | 349 | |
350 | | - if ( !file_exists( $params['srcPath'] ) ) { |
351 | | - $err = "File seems to be missing: {$params['srcPath']}"; |
352 | | - wfDebug( "$err\n" ); |
353 | | - $errMsg = wfMsg ( 'thumbnail_image-missing', $params['srcPath'] ); |
354 | | - return $this->getMediaTransformError( $params, $errMsg ); |
355 | | - } |
| 350 | + if ( !file_exists( $params['srcPath'] ) ) { |
| 351 | + $err = "File seems to be missing: {$params['srcPath']}"; |
| 352 | + wfDebug( "$err\n" ); |
| 353 | + $errMsg = wfMsg ( 'thumbnail_image-missing', $params['srcPath'] ); |
| 354 | + return $this->getMediaTransformError( $params, $errMsg ); |
| 355 | + } |
356 | 356 | |
357 | | - $src_image = call_user_func( $loader, $params['srcPath'] ); |
358 | | - $dst_image = imagecreatetruecolor( $params['physicalWidth'], |
359 | | - $params['physicalHeight'] ); |
| 357 | + $src_image = call_user_func( $loader, $params['srcPath'] ); |
| 358 | + $dst_image = imagecreatetruecolor( $params['physicalWidth'], |
| 359 | + $params['physicalHeight'] ); |
360 | 360 | |
361 | | - // Initialise the destination image to transparent instead of |
362 | | - // the default solid black, to support PNG and GIF transparency nicely |
363 | | - $background = imagecolorallocate( $dst_image, 0, 0, 0 ); |
364 | | - imagecolortransparent( $dst_image, $background ); |
365 | | - imagealphablending( $dst_image, false ); |
| 361 | + // Initialise the destination image to transparent instead of |
| 362 | + // the default solid black, to support PNG and GIF transparency nicely |
| 363 | + $background = imagecolorallocate( $dst_image, 0, 0, 0 ); |
| 364 | + imagecolortransparent( $dst_image, $background ); |
| 365 | + imagealphablending( $dst_image, false ); |
366 | 366 | |
367 | | - if ( $colorStyle == 'palette' ) { |
368 | | - // Don't resample for paletted GIF images. |
369 | | - // It may just uglify them, and completely breaks transparency. |
370 | | - imagecopyresized( $dst_image, $src_image, |
371 | | - 0,0,0,0, |
372 | | - $params['physicalWidth'], $params['physicalHeight'], |
373 | | - imagesx( $src_image ), imagesy( $src_image ) ); |
374 | | - } else { |
375 | | - imagecopyresampled( $dst_image, $src_image, |
376 | | - 0,0,0,0, |
377 | | - $params['physicalWidth'], $params['physicalHeight'], |
378 | | - imagesx( $src_image ), imagesy( $src_image ) ); |
379 | | - } |
| 367 | + if ( $colorStyle == 'palette' ) { |
| 368 | + // Don't resample for paletted GIF images. |
| 369 | + // It may just uglify them, and completely breaks transparency. |
| 370 | + imagecopyresized( $dst_image, $src_image, |
| 371 | + 0, 0, 0, 0, |
| 372 | + $params['physicalWidth'], $params['physicalHeight'], |
| 373 | + imagesx( $src_image ), imagesy( $src_image ) ); |
| 374 | + } else { |
| 375 | + imagecopyresampled( $dst_image, $src_image, |
| 376 | + 0, 0, 0, 0, |
| 377 | + $params['physicalWidth'], $params['physicalHeight'], |
| 378 | + imagesx( $src_image ), imagesy( $src_image ) ); |
| 379 | + } |
380 | 380 | |
381 | | - imagesavealpha( $dst_image, true ); |
| 381 | + imagesavealpha( $dst_image, true ); |
382 | 382 | |
383 | | - call_user_func( $saveType, $dst_image, $params['dstPath'] ); |
384 | | - imagedestroy( $dst_image ); |
385 | | - imagedestroy( $src_image ); |
386 | | - |
387 | | - return false; # No error |
| 383 | + call_user_func( $saveType, $dst_image, $params['dstPath'] ); |
| 384 | + imagedestroy( $dst_image ); |
| 385 | + imagedestroy( $src_image ); |
| 386 | + |
| 387 | + return false; # No error |
388 | 388 | } |
389 | 389 | |
390 | 390 | /** |
— | — | @@ -403,14 +403,14 @@ |
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
407 | | - * Escape a string for ImageMagick's input filenames. See ExpandFilenames() |
| 407 | + * Escape a string for ImageMagick's input filenames. See ExpandFilenames() |
408 | 408 | * and GetPathComponent() in magick/utility.c. |
409 | 409 | * |
410 | 410 | * This won't work with an initial ~ or @, so input files should be prefixed |
411 | | - * with the directory name. |
| 411 | + * with the directory name. |
412 | 412 | * |
413 | 413 | * Glob character unescaping is broken in ImageMagick before 6.6.1-5, but |
414 | | - * it's broken in a way that doesn't involve trying to convert every file |
| 414 | + * it's broken in a way that doesn't involve trying to convert every file |
415 | 415 | * in a directory, so we're better off escaping and waiting for the bugfix |
416 | 416 | * to filter down to users. |
417 | 417 | * |
— | — | @@ -421,7 +421,7 @@ |
422 | 422 | # Die on initial metacharacters (caller should prepend path) |
423 | 423 | $firstChar = substr( $path, 0, 1 ); |
424 | 424 | if ( $firstChar === '~' || $firstChar === '@' ) { |
425 | | - throw new MWException( __METHOD__.': cannot escape this path name' ); |
| 425 | + throw new MWException( __METHOD__ . ': cannot escape this path name' ); |
426 | 426 | } |
427 | 427 | |
428 | 428 | # Escape glob chars |
— | — | @@ -431,7 +431,7 @@ |
432 | 432 | } |
433 | 433 | |
434 | 434 | /** |
435 | | - * Escape a string for ImageMagick's output filename. See |
| 435 | + * Escape a string for ImageMagick's output filename. See |
436 | 436 | * InterpretImageFilename() in magick/image.c. |
437 | 437 | */ |
438 | 438 | function escapeMagickOutput( $path, $scene = false ) { |
— | — | @@ -440,7 +440,7 @@ |
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
444 | | - * Armour a string against ImageMagick's GetPathComponent(). This is a |
| 444 | + * Armour a string against ImageMagick's GetPathComponent(). This is a |
445 | 445 | * helper function for escapeMagickInput() and escapeMagickOutput(). |
446 | 446 | * |
447 | 447 | * @param $path string The file path |
— | — | @@ -454,11 +454,11 @@ |
455 | 455 | // OK, it's a drive letter |
456 | 456 | // ImageMagick has a similar exception, see IsMagickConflict() |
457 | 457 | } else { |
458 | | - throw new MWException( __METHOD__.': unexpected colon character in path name' ); |
| 458 | + throw new MWException( __METHOD__ . ': unexpected colon character in path name' ); |
459 | 459 | } |
460 | 460 | } |
461 | 461 | |
462 | | - # If there are square brackets, add a do-nothing scene specification |
| 462 | + # If there are square brackets, add a do-nothing scene specification |
463 | 463 | # to force a literal interpretation |
464 | 464 | if ( $scene === false ) { |
465 | 465 | if ( strpos( $path, '[' ) !== false ) { |
— | — | @@ -480,15 +480,15 @@ |
481 | 481 | global $wgMemc; |
482 | 482 | |
483 | 483 | $cache = $wgMemc->get( "imagemagick-version" ); |
484 | | - if( !$cache ) { |
| 484 | + if ( !$cache ) { |
485 | 485 | global $wgImageMagickConvertCommand; |
486 | 486 | $cmd = wfEscapeShellArg( $wgImageMagickConvertCommand ) . ' -version'; |
487 | | - wfDebug( __METHOD__.": Running convert -version\n" ); |
| 487 | + wfDebug( __METHOD__ . ": Running convert -version\n" ); |
488 | 488 | $retval = ''; |
489 | 489 | $return = wfShellExec( $cmd, $retval ); |
490 | | - $x = preg_match('/Version: ImageMagick ([0-9]*\.[0-9]*\.[0-9]*)/', $return, $matches); |
491 | | - if( $x != 1 ) { |
492 | | - wfDebug( __METHOD__.": ImageMagick version check failed\n" ); |
| 490 | + $x = preg_match( '/Version: ImageMagick ([0-9]*\.[0-9]*\.[0-9]*)/', $return, $matches ); |
| 491 | + if ( $x != 1 ) { |
| 492 | + wfDebug( __METHOD__ . ": ImageMagick version check failed\n" ); |
493 | 493 | return null; |
494 | 494 | } |
495 | 495 | $wgMemc->set( "imagemagick-version", $matches[1], 3600 ); |
— | — | @@ -505,7 +505,7 @@ |
506 | 506 | |
507 | 507 | function getMetadata( $image, $filename ) { |
508 | 508 | global $wgShowEXIF; |
509 | | - if( $wgShowEXIF && file_exists( $filename ) ) { |
| 509 | + if ( $wgShowEXIF && file_exists( $filename ) ) { |
510 | 510 | $exif = new Exif( $filename ); |
511 | 511 | $data = $exif->getFilteredData(); |
512 | 512 | if ( $data ) { |
— | — | @@ -540,7 +540,7 @@ |
541 | 541 | $exif['MEDIAWIKI_EXIF_VERSION'] != Exif::version() ) |
542 | 542 | { |
543 | 543 | # Wrong version |
544 | | - wfDebug( __METHOD__.": wrong version\n" ); |
| 544 | + wfDebug( __METHOD__ . ": wrong version\n" ); |
545 | 545 | return false; |
546 | 546 | } |
547 | 547 | return true; |
— | — | @@ -556,9 +556,9 @@ |
557 | 557 | function visibleMetadataFields() { |
558 | 558 | $fields = array(); |
559 | 559 | $lines = explode( "\n", wfMsgForContent( 'metadata-fields' ) ); |
560 | | - foreach( $lines as $line ) { |
| 560 | + foreach ( $lines as $line ) { |
561 | 561 | $matches = array(); |
562 | | - if( preg_match( '/^\\*\s*(.*?)\s*$/', $line, $matches ) ) { |
| 562 | + if ( preg_match( '/^\\*\s*(.*?)\s*$/', $line, $matches ) ) { |
563 | 563 | $fields[] = $matches[1]; |
564 | 564 | } |
565 | 565 | } |