(bug 27809) Check for availability of imagerotate function before using it
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Wed, 2 Mar 2011 19:42:30 +0000 (19:42 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Wed, 2 Mar 2011 19:42:30 +0000 (19:42 +0000)
includes/media/Bitmap.php

index 7e93994..cc7b052 100644 (file)
@@ -402,7 +402,8 @@ class BitmapHandler extends ImageHandler {
                }
 
                $src_image = call_user_func( $loader, $params['srcPath'] );
-               $rotation = $this->getRotation( $image );
+               
+               $rotation = function_exists( 'imagerotate' ) ? $this->getRotation( $image ) : 0;
                if ( $rotation == 90 || $rotation == 270 ) {
                        # We'll resize before rotation, so swap the dimensions again
                        $width = $params['physicalHeight'];
@@ -698,7 +699,18 @@ class BitmapHandler extends ImageHandler {
         */
        public static function canRotate() {
                $scaler = self::getScalerType( null, false );
-               return $scaler == 'im' || $scaler == 'gd';
+               switch ( $scaler ) {
+                       case 'im':
+                               # ImageMagick supports autorotation
+                               return true;
+                       case 'gd':
+                               # GD's imagerotate function is used to rotate images, but not
+                               # all precompiled PHP versions have that function
+                               return function_exists( 'imagerotate' );
+                       default:
+                               # Other scalers don't support rotation
+                               return false;
+               }
        }
        
        /**