Index: trunk/phase3/includes/media/Bitmap.php |
— | — | @@ -27,12 +27,12 @@ |
28 | 28 | $mimeType = $image->getMimeType(); |
29 | 29 | $srcWidth = $image->getWidth( $params['page'] ); |
30 | 30 | $srcHeight = $image->getHeight( $params['page'] ); |
31 | | - |
| 31 | + |
32 | 32 | if ( self::canRotate() ) { |
33 | 33 | $rotation = $this->getRotation( $image ); |
34 | 34 | if ( $rotation == 90 || $rotation == 270 ) { |
35 | 35 | wfDebug( __METHOD__ . ": Swapping width and height because the file will be rotated $rotation degrees\n" ); |
36 | | - |
| 36 | + |
37 | 37 | $width = $params['width']; |
38 | 38 | $params['width'] = $params['height']; |
39 | 39 | $params['height'] = $width; |
— | — | @@ -136,7 +136,7 @@ |
137 | 137 | wfDebug( __METHOD__ . ": Unable to create thumbnail destination directory, falling back to client scaling\n" ); |
138 | 138 | return $this->getClientScalingThumbnailImage( $image, $scalerParams ); |
139 | 139 | } |
140 | | - |
| 140 | + |
141 | 141 | # Try a hook |
142 | 142 | $mto = null; |
143 | 143 | wfRunHooks( 'BitmapHandlerTransform', array( $this, $image, &$scalerParams, &$mto ) ); |
— | — | @@ -144,7 +144,7 @@ |
145 | 145 | wfDebug( __METHOD__ . ": Hook to BitmapHandlerTransform created an mto\n" ); |
146 | 146 | $scaler = 'hookaborted'; |
147 | 147 | } |
148 | | - |
| 148 | + |
149 | 149 | switch ( $scaler ) { |
150 | 150 | case 'hookaborted': |
151 | 151 | # Handled by the hook above |
— | — | @@ -181,16 +181,16 @@ |
182 | 182 | $scalerParams['clientHeight'], $dstPath ); |
183 | 183 | } |
184 | 184 | } |
185 | | - |
| 185 | + |
186 | 186 | /** |
187 | | - * Returns which scaler type should be used. Creates parent directories |
| 187 | + * Returns which scaler type should be used. Creates parent directories |
188 | 188 | * for $dstPath and returns 'client' on error |
189 | | - * |
| 189 | + * |
190 | 190 | * @return string client,im,custom,gd |
191 | 191 | */ |
192 | 192 | protected static function getScalerType( $dstPath, $checkDstPath = true ) { |
193 | 193 | global $wgUseImageResize, $wgUseImageMagick, $wgCustomConvertCommand; |
194 | | - |
| 194 | + |
195 | 195 | if ( !$dstPath && $checkDstPath ) { |
196 | 196 | # No output path available, client side scaling only |
197 | 197 | $scaler = 'client'; |
— | — | @@ -207,7 +207,7 @@ |
208 | 208 | } else { |
209 | 209 | $scaler = 'client'; |
210 | 210 | } |
211 | | - |
| 211 | + |
212 | 212 | if ( $scaler != 'client' && $dstPath ) { |
213 | 213 | if ( !wfMkdirParents( dirname( $dstPath ) ) ) { |
214 | 214 | # Unable to create a path for the thumbnail |
— | — | @@ -229,7 +229,7 @@ |
230 | 230 | return new ThumbnailImage( $image, $image->getURL(), |
231 | 231 | $params['clientWidth'], $params['clientHeight'], $params['srcPath'] ); |
232 | 232 | } |
233 | | - |
| 233 | + |
234 | 234 | /** |
235 | 235 | * Transform an image using ImageMagick |
236 | 236 | * |
— | — | @@ -277,7 +277,7 @@ |
278 | 278 | // We optimize the output, but -optimize is broken, |
279 | 279 | // use optimizeTransparency instead (bug 11822) |
280 | 280 | if ( version_compare( $this->getMagickVersion(), "6.3.5" ) >= 0 ) { |
281 | | - $animation_post = '-fuzz 5% -layers optimizeTransparency +map'; |
| 281 | + $animation_post = '-fuzz 5% -layers optimizeTransparency'; |
282 | 282 | } |
283 | 283 | } |
284 | 284 | } |
— | — | @@ -321,10 +321,10 @@ |
322 | 322 | |
323 | 323 | return false; # No error |
324 | 324 | } |
325 | | - |
| 325 | + |
326 | 326 | /** |
327 | 327 | * Transform an image using the Imagick PHP extension |
328 | | - * |
| 328 | + * |
329 | 329 | * @param $image File File associated with this thumbnail |
330 | 330 | * @param $params array Array with scaler params |
331 | 331 | * |
— | — | @@ -332,11 +332,11 @@ |
333 | 333 | */ |
334 | 334 | protected function transformImageMagickExt( $image, $params ) { |
335 | 335 | global $wgSharpenReductionThreshold, $wgSharpenParameter, $wgMaxAnimatedGifArea; |
336 | | - |
| 336 | + |
337 | 337 | try { |
338 | 338 | $im = new Imagick(); |
339 | 339 | $im->readImage( $params['srcPath'] ); |
340 | | - |
| 340 | + |
341 | 341 | if ( $params['mimeType'] == 'image/jpeg' ) { |
342 | 342 | // Sharpening, see bug 6193 |
343 | 343 | if ( ( $params['physicalWidth'] + $params['physicalHeight'] ) |
— | — | @@ -360,7 +360,7 @@ |
361 | 361 | $im = $im->coalesceImages(); |
362 | 362 | } |
363 | 363 | } |
364 | | - |
| 364 | + |
365 | 365 | $rotation = $this->getRotation( $image ); |
366 | 366 | if ( $rotation == 90 || $rotation == 270 ) { |
367 | 367 | // We'll resize before rotation, so swap the dimensions again |
— | — | @@ -368,11 +368,11 @@ |
369 | 369 | $height = $params['physicalWidth']; |
370 | 370 | } else { |
371 | 371 | $width = $params['physicalWidth']; |
372 | | - $height = $params['physicalHeight']; |
| 372 | + $height = $params['physicalHeight']; |
373 | 373 | } |
374 | | - |
| 374 | + |
375 | 375 | $im->setImageBackgroundColor( new ImagickPixel( 'white' ) ); |
376 | | - |
| 376 | + |
377 | 377 | // Call Imagick::thumbnailImage on each frame |
378 | 378 | foreach ( $im as $i => $frame ) { |
379 | 379 | if ( !$frame->thumbnailImage( $width, $height, /* fit */ false ) ) { |
— | — | @@ -380,13 +380,13 @@ |
381 | 381 | } |
382 | 382 | } |
383 | 383 | $im->setImageDepth( 8 ); |
384 | | - |
| 384 | + |
385 | 385 | if ( $rotation ) { |
386 | 386 | if ( !$im->rotateImage( new ImagickPixel( 'white' ), 360 - $rotation ) ) { |
387 | 387 | return $this->getMediaTransformError( $params, "Error rotating $rotation degrees" ); |
388 | 388 | } |
389 | 389 | } |
390 | | - |
| 390 | + |
391 | 391 | if ( $this->isAnimatedImage( $image ) ) { |
392 | 392 | wfDebug( __METHOD__ . ": Writing animated thumbnail\n" ); |
393 | 393 | // This is broken somehow... can't find out how to fix it |
— | — | @@ -395,16 +395,16 @@ |
396 | 396 | $result = $im->writeImage( $params['dstPath'] ); |
397 | 397 | } |
398 | 398 | if ( !$result ) { |
399 | | - return $this->getMediaTransformError( $params, |
| 399 | + return $this->getMediaTransformError( $params, |
400 | 400 | "Unable to write thumbnail to {$params['dstPath']}" ); |
401 | 401 | } |
402 | 402 | |
403 | 403 | } catch ( ImagickException $e ) { |
404 | | - return $this->getMediaTransformError( $params, $e->getMessage() ); |
| 404 | + return $this->getMediaTransformError( $params, $e->getMessage() ); |
405 | 405 | } |
406 | | - |
| 406 | + |
407 | 407 | return false; |
408 | | - |
| 408 | + |
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
— | — | @@ -453,7 +453,7 @@ |
454 | 454 | } |
455 | 455 | /** |
456 | 456 | * Get a MediaTransformError with error 'thumbnail_error' |
457 | | - * |
| 457 | + * |
458 | 458 | * @param $params array Parameter array as passed to the transform* functions |
459 | 459 | * @param $errMsg string Error message |
460 | 460 | * @return MediaTransformError |
— | — | @@ -507,7 +507,7 @@ |
508 | 508 | } |
509 | 509 | |
510 | 510 | $src_image = call_user_func( $loader, $params['srcPath'] ); |
511 | | - |
| 511 | + |
512 | 512 | $rotation = function_exists( 'imagerotate' ) ? $this->getRotation( $image ) : 0; |
513 | 513 | if ( $rotation == 90 || $rotation == 270 ) { |
514 | 514 | # We'll resize before rotation, so swap the dimensions again |
— | — | @@ -515,7 +515,7 @@ |
516 | 516 | $height = $params['physicalWidth']; |
517 | 517 | } else { |
518 | 518 | $width = $params['physicalWidth']; |
519 | | - $height = $params['physicalHeight']; |
| 519 | + $height = $params['physicalHeight']; |
520 | 520 | } |
521 | 521 | $dst_image = imagecreatetruecolor( $width, $height ); |
522 | 522 | |
— | — | @@ -538,13 +538,13 @@ |
539 | 539 | $width, $height, |
540 | 540 | imagesx( $src_image ), imagesy( $src_image ) ); |
541 | 541 | } |
542 | | - |
| 542 | + |
543 | 543 | if ( $rotation % 360 != 0 && $rotation % 90 == 0 ) { |
544 | 544 | $rot_image = imagerotate( $dst_image, $rotation, 0 ); |
545 | 545 | imagedestroy( $dst_image ); |
546 | 546 | $dst_image = $rot_image; |
547 | 547 | } |
548 | | - |
| 548 | + |
549 | 549 | imagesavealpha( $dst_image, true ); |
550 | 550 | |
551 | 551 | call_user_func( $saveType, $dst_image, $params['dstPath'] ); |
— | — | @@ -671,9 +671,9 @@ |
672 | 672 | } |
673 | 673 | |
674 | 674 | /** |
675 | | - * Try to read out the orientation of the file and return the angle that |
| 675 | + * Try to read out the orientation of the file and return the angle that |
676 | 676 | * the file needs to be rotated to be viewed |
677 | | - * |
| 677 | + * |
678 | 678 | * @param $file File |
679 | 679 | * @return int 0, 90, 180 or 270 |
680 | 680 | */ |
— | — | @@ -701,7 +701,7 @@ |
702 | 702 | |
703 | 703 | /** |
704 | 704 | * Returns whether the current scaler supports rotation (im and gd do) |
705 | | - * |
| 705 | + * |
706 | 706 | * @return bool |
707 | 707 | */ |
708 | 708 | public static function canRotate() { |
— | — | @@ -722,11 +722,11 @@ |
723 | 723 | return false; |
724 | 724 | } |
725 | 725 | } |
726 | | - |
| 726 | + |
727 | 727 | /** |
728 | | - * Rerurns whether the file needs to be rendered. Returns true if the |
| 728 | + * Rerurns whether the file needs to be rendered. Returns true if the |
729 | 729 | * file requires rotation and we are able to rotate it. |
730 | | - * |
| 730 | + * |
731 | 731 | * @param $file File |
732 | 732 | * @return bool |
733 | 733 | */ |