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 f62f105..4f33332 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php @@ -8,6 +8,7 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation\gd; use Drupal\Component\Utility\Color; +use Drupal\Component\Utility\Rectangle; /** * Defines GD2 rotate operation. @@ -99,12 +100,9 @@ protected function execute(array $arguments) { } // Check that enough memory is available. - // @todo more accurate width and height of the image after rotation will be - // available after #1551686. In the meantime, the maximum width and height - // can never exceed the length of the diagonal of the rectangle represented - // by the image. - $diagonal = (int) sqrt(pow($this->getToolkit()->getWidth(), 2) + pow($this->getToolkit()->getHeight(), 2)) + 1; - if (!$this->getToolkit()->checkAvailableMemory($diagonal, $diagonal)) { + $rect = new Rectangle($this->getToolkit()->getWidth(), $this->getToolkit()->getHeight()); + $rect = $rect->rotate($arguments['degrees']); + if (!$this->getToolkit()->checkAvailableMemory($rect->getBoundingWidth(), $rect->getBoundingHeight())) { $memory = $this->getToolkit()->getMemoryInfo(); throw new \RuntimeException("Not enough memory (required: {$memory['required']['size']} {$memory['required']['unit']}, free: {$memory['free']['size']} {$memory['free']['unit']}, total: {$memory['total']['size']} {$memory['total']['unit']}) to perform the image '{$this->getPluginId()}' operation"); }