diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php
index 0284b42..a0b3c8e 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php
@@ -42,13 +42,40 @@ protected function arguments() {
    * {@inheritdoc}
    */
   protected function validateArguments(array $arguments) {
+    // Assure integer for degrees.
+    $arguments['degrees'] = (int) round($arguments['degrees']);
+
+    // Fail when degrees are not in -360 to 360 range.
+    if ($arguments['degrees'] < -360 || $arguments['degrees'] > 360) {
+      throw new \InvalidArgumentException("Invalid degrees ('{$arguments['degrees']}') specified for the image 'rotate' operation");
+    }
+
+    // Assure background color is a valid hex string.
+    if ($arguments['background'] && !Color::validateHex($arguments['background'])) {
+      throw new \InvalidArgumentException("Invalid background color ('{$arguments['background']}') specified for the image 'rotate' operation");
+    }
+
+    return $arguments;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function execute(array $arguments) {
+    // PHP installations using non-bundled GD do not have imagerotate.
+    if (!function_exists('imagerotate')) {
+      $this->logger->notice('The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', array('%file' => $this->getToolkit()->getImage()->getSource()));
+      return FALSE;
+    }
+
     // PHP 5.5 GD bug: https://bugs.php.net/bug.php?id=65148: To prevent buggy
     // behavior on negative multiples of 90 degrees we convert any negative
     // angle to a positive one between 0 and 360 degrees.
-    $arguments['degrees'] -= floor($arguments['degrees'] / 360) * 360;
+    $degrees = $arguments['degrees'];
+    $degrees -= floor($degrees / 360) * 360;
 
-    // Validate or set background color argument.
-    if (!empty($arguments['background'])) {
+    // Set background color argument.
+    if ($arguments['background']) {
       // Validate the background color: Color::hexToRgb does so for us.
       $background = Color::hexToRgb($arguments['background']) + array( 'alpha' => 0 );
     }
@@ -57,7 +84,7 @@ protected function validateArguments(array $arguments) {
       $background = array('red' => 255, 'green' => 255, 'blue' => 255, 'alpha' => 127);
     }
     // Store the color index for the background as that is what GD uses.
-    $arguments['background_idx'] = imagecolorallocatealpha($this->getToolkit()->getResource(), $background['red'], $background['green'], $background['blue'], $background['alpha']);
+    $background_idx = imagecolorallocatealpha($this->getToolkit()->getResource(), $background['red'], $background['green'], $background['blue'], $background['alpha']);
 
     if ($this->getToolkit()->getType() === IMAGETYPE_GIF) {
       // GIF does not work with a transparency channel, but can define 1 color
@@ -68,43 +95,31 @@ protected function validateArguments(array $arguments) {
       if ($gif_transparent_id !== -1) {
         // The gif already has a transparent color set: remember it to set it on
         // the rotated image as well.
-        $arguments['gif_transparent_color'] = imagecolorsforindex($this->getToolkit()->getResource(), $gif_transparent_id);
+        $gif_transparent_color = imagecolorsforindex($this->getToolkit()->getResource(), $gif_transparent_id);
 
         if ($background['alpha'] >= 127) {
           // We want a transparent background: use the color already set to act
           // as transparent, as background.
-          $arguments['background_idx'] = $gif_transparent_id;
+          $background_idx = $gif_transparent_id;
         }
       }
       else {
         // The gif does not currently have a transparent color set.
         if ($background['alpha'] >= 127) {
           // But as the background is transparent, it should get one.
-          $arguments['gif_transparent_color'] = $background;
+          $gif_transparent_color = $background;
         }
       }
     }
 
-    return $arguments;
-  }
-
-  /**
-   * {@inheritdoc}
-   */
-  protected function execute(array $arguments) {
-    // PHP installations using non-bundled GD do not have imagerotate.
-    if (!function_exists('imagerotate')) {
-      $this->logger->notice('The image %file could not be rotated because the imagerotate() function is not available in this PHP installation.', array('%file' => $this->getToolkit()->getImage()->getSource()));
-      return FALSE;
-    }
-
-    $this->getToolkit()->setResource(imagerotate($this->getToolkit()->getResource(), 360 - $arguments['degrees'], $arguments['background_idx']));
+    // Perform rotation via imagerotate().
+    $this->getToolkit()->setResource(imagerotate($this->getToolkit()->getResource(), 360 - $degrees, $background_idx));
 
     // GIFs need to reassign the transparent color after performing the rotate,
     // but only do so, if the image already had transparency of its own, or the
     // rotate added a transparent background.
-    if (!empty($arguments['gif_transparent_color'])) {
-      $transparent_idx = imagecolorexactalpha($this->getToolkit()->getResource(), $arguments['gif_transparent_color']['red'], $arguments['gif_transparent_color']['green'], $arguments['gif_transparent_color']['blue'], $arguments['gif_transparent_color']['alpha']);
+    if (!empty($gif_transparent_color)) {
+      $transparent_idx = imagecolorexactalpha($this->getToolkit()->getResource(), $gif_transparent_color['red'], $gif_transparent_color['green'], $gif_transparent_color['blue'], $gif_transparent_color['alpha']);
       imagecolortransparent($this->getToolkit()->getResource(), $transparent_idx);
     }
 
diff --git a/core/tests/Drupal/Tests/Core/Image/ImageTest.php b/core/tests/Drupal/Tests/Core/Image/ImageTest.php
index e81bb76..d0cdf51 100644
--- a/core/tests/Drupal/Tests/Core/Image/ImageTest.php
+++ b/core/tests/Drupal/Tests/Core/Image/ImageTest.php
@@ -14,6 +14,7 @@
 /**
  * Tests the image class.
  *
+ * @coversDefaultClass \Drupal\Core\Image\Image
  * @group Image
  */
 class ImageTest extends UnitTestCase {
@@ -64,9 +65,12 @@ protected function setUp() {
    */
   protected function getToolkitMock(array $stubs = array()) {
     $mock_builder = $this->getMockBuilder('Drupal\system\Plugin\ImageToolkit\GDToolkit');
+    $operation_manager = $this->getMock('Drupal\core\ImageToolkit\ImageToolkitOperationManagerInterface');
+    $config_factory = $this->getMock('Drupal\Core\Config\ConfigFactoryInterface');
+    $logger = $this->getMock('Psr\Log\LoggerInterface');
     $stubs = array_merge(array('getPluginId', 'save'), $stubs);
     return $mock_builder
-      ->disableOriginalConstructor()
+      ->setConstructorArgs([[], '', [], $operation_manager, $logger, $config_factory])
       ->setMethods($stubs)
       ->getMock();
   }
@@ -452,8 +456,44 @@ public function testRotate() {
       ->method('execute')
       ->will($this->returnArgument(0));
 
-    $ret = $this->image->rotate(90);
+    $ret = $this->image->rotate(90, '#00FF00');
     $this->assertEquals(90, $ret['degrees']);
+    $this->assertEquals('#00FF00', $ret['background']);
+  }
+
+  /**
+   * @covers ::rotate
+   */
+  public function testRotateRounding() {
+    $this->getTestImageForOperation('Rotate');
+    $this->toolkitOperation->expects($this->once())
+      ->method('execute')
+      ->will($this->returnArgument(0));
+
+    $ret = $this->image->rotate(14.7);
+    $this->assertEquals(15, $ret['degrees']);
+  }
+
+  /**
+   * @covers ::rotate
+   */
+  public function testRotateExceedingDegrees() {
+    $this->getTestImageForOperation('Rotate');
+    $this->toolkitOperation->expects($this->never())
+      ->method('execute');
+
+    $ret = $this->image->rotate(465);
+  }
+
+  /**
+   * @covers ::rotate
+   */
+  public function testRotateWrongBackgroundColor() {
+    $this->getTestImageForOperation('Rotate');
+    $this->toolkitOperation->expects($this->never())
+      ->method('execute');
+
+    $ret = $this->image->rotate(46, '#foo');
   }
 
 }
