diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php
index 8738500..83a7381 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php
@@ -181,6 +181,7 @@ protected function load() {
           'height' => imagesy($resource),
           'extension' => image_type_to_extension($this->getType(), FALSE),
           'transparent_color' => $this->getTransparentColor(),
+          'is_temp' => TRUE,
         );
         if ($this->apply('create_new', $data)) {
           imagecopy($this->getResource(), $resource, 0, 0, 0, 0, imagesx($resource), imagesy($resource));
diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Convert.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Convert.php
index 93b9360..bacd44f 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Convert.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Convert.php
@@ -58,7 +58,8 @@ protected function execute(array $arguments) {
       'width' => $width,
       'height' => $height,
       'extension' => $arguments['extension'],
-      'transparent_color' => $this->getToolkit()->getTransparentColor()
+      'transparent_color' => $this->getToolkit()->getTransparentColor(),
+      'is_temp' => TRUE,
     );
     if ($this->getToolkit()->apply('create_new', $data)) {
       if (imagecopyresampled($this->getToolkit()->getResource(), $original_resource, 0, 0, 0, 0, $width, $height, $width, $height)) {
diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/CreateNew.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/CreateNew.php
index 00fecad..f13b163 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/CreateNew.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/CreateNew.php
@@ -44,6 +44,11 @@ protected function arguments() {
         'required' => FALSE,
         'default' => '#ffffff',
       ),
+      'is_temp' => array(
+        'description' => 'GD internal - indicates that the original GD resource should not be destroyed as a calling operation relies on it.',
+        'required' => FALSE,
+        'default' => FALSE,
+      ),
     );
   }
 
@@ -83,6 +88,9 @@ protected function execute(array $arguments) {
     // Get the image type.
     $type = $this->getToolkit()->extensionToImageType($arguments['extension']);
 
+    // Store the original GD resource.
+    $original_res = $this->getToolkit()->getResource();
+
     // Create the resource.
     if (!$res = imagecreatetruecolor($arguments['width'], $arguments['height'])) {
       return FALSE;
@@ -120,6 +128,12 @@ protected function execute(array $arguments) {
     // Update the toolkit properties.
     $this->getToolkit()->setType($type);
     $this->getToolkit()->setResource($res);
+
+    // Destroy the original resource if it is not needed by other operations.
+    if (!$arguments['is_temp'] && is_resource($original_res)) {
+      imagedestroy($original_res);
+    }
+
     return TRUE;
   }
 
diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php
index 21d59f4..49c71d3 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php
@@ -88,7 +88,8 @@ protected function execute(array $arguments) {
       'width' => $arguments['width'],
       'height' => $arguments['height'],
       'extension' => image_type_to_extension($this->getToolkit()->getType(), FALSE),
-      'transparent_color' => $this->getToolkit()->getTransparentColor()
+      'transparent_color' => $this->getToolkit()->getTransparentColor(),
+      'is_temp' => TRUE,
     );
     if ($this->getToolkit()->apply('create_new', $data)) {
       if (imagecopyresampled($this->getToolkit()->getResource(), $original_resource, 0, 0, $arguments['x'], $arguments['y'], $arguments['width'], $arguments['height'], $arguments['width'], $arguments['height'])) {
diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php
index be72427..acccd37 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php
@@ -67,7 +67,8 @@ protected function execute(array $arguments = array()) {
       'width' => $arguments['width'],
       'height' => $arguments['height'],
       'extension' => image_type_to_extension($this->getToolkit()->getType(), FALSE),
-      'transparent_color' => $this->getToolkit()->getTransparentColor()
+      'transparent_color' => $this->getToolkit()->getTransparentColor(),
+      'is_temp' => TRUE,
     );
     if ($this->getToolkit()->apply('create_new', $data)) {
       if (imagecopyresampled($this->getToolkit()->getResource(), $original_resource, 0, 0, 0, 0, $arguments['width'], $arguments['height'], imagesx($original_resource), imagesy($original_resource))) {
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..37632bc 100644
--- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php
+++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php
@@ -98,17 +98,25 @@ protected function execute(array $arguments) {
       return FALSE;
     }
 
-    $this->getToolkit()->setResource(imagerotate($this->getToolkit()->getResource(), 360 - $arguments['degrees'], $arguments['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']);
-      imagecolortransparent($this->getToolkit()->getResource(), $transparent_idx);
+    // Stores the original GD resource.
+    $original_res = $this->getToolkit()->getResource();
+
+    if ($new_res = imagerotate($this->getToolkit()->getResource(), 360 - $arguments['degrees'], $arguments['background_idx'])) {
+      $this->getToolkit()->setResource($new_res);
+      imagedestroy($original_res);
+
+      // 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']);
+        imagecolortransparent($this->getToolkit()->getResource(), $transparent_idx);
+      }
+
+      return TRUE;
     }
 
-    return TRUE;
+    return FALSE;
   }
 
 }
diff --git a/core/modules/system/src/Tests/Image/ToolkitGdTest.php b/core/modules/system/src/Tests/Image/ToolkitGdTest.php
index d7f55dc..7d4a7c6 100644
--- a/core/modules/system/src/Tests/Image/ToolkitGdTest.php
+++ b/core/modules/system/src/Tests/Image/ToolkitGdTest.php
@@ -278,9 +278,19 @@ function testManipulations() {
           }
         }
 
+        // Store the original GD resource.
+        $old_res = $toolkit->getResource();
+
         // Perform our operation.
         $image->apply($values['function'], $values['arguments']);
 
+        // If the operation replaced the resource, check that the old one has
+        // been destroyed.
+        $new_res = $toolkit->getResource();
+        if ($new_res !== $old_res) {
+          $this->assertFalse(is_resource($old_res), SafeMarkup::format("'%operation' destroyed the original resource.", ['%operation' => $values['function']]));
+        }
+
         // To keep from flooding the test with assert values, make a general
         // value for whether each group of values fail.
         $correct_dimensions_real = TRUE;
@@ -389,6 +399,16 @@ function testManipulations() {
       }
     }
 
+    // Test that CreateNew does not leave orphaned GD resources.
+    $image = $this->imageFactory->get($file_path);
+    for ($i = 0; $i < 2; $i++) {
+      $old_res = $image->getToolkit()->getResource();
+      $image->createNew(2000, 2000);
+      $new_res = $image->getToolkit()->getResource();
+      $this->assertFalse(is_resource($old_res), 'CreateNew destroyed the original resource.');
+      $this->assertTrue(is_resource($new_res), 'CreateNew has created a new resource.');
+    }
+
     // Test failures of CreateNew.
     $image = $this->imageFactory->get();
     $image->createNew(-50, 20);
