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; } }