Browse Source

fix Image::rotate(): unexpected result for angle == 0 and angle >= 360

Fabian Peter Hammerle 7 years ago
parent
commit
a2a02f8657
1 changed files with 7 additions and 4 deletions
  1. 7 4
      Image.php

+ 7 - 4
Image.php

@@ -59,14 +59,17 @@ class Image
     }
 
     /**
-     * @param float $angle
+     * @param float $angle anticlockwise
      * @return void
      */
     public function rotate($angle)
     {
-        $resource = imagerotate($this->_resource, $angle, 0);
-        imagedestroy($this->_resource);
-        $this->_resource = $resource;
+        $angle = fmod($angle, 360);
+        if(abs($angle) > 1e-10) {
+            $resource = imagerotate($this->_resource, $angle, 0);
+            imagedestroy($this->_resource);
+            $this->_resource = $resource;
+        }
     }
 
     /**