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 0860b11..98561d9 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Rotate.php @@ -40,14 +40,10 @@ protected function arguments() { * {@inheritdoc} */ protected function validateArguments(array $arguments) { - // Convert any negative angle to a positive angle. Reason: - // PHP 5.5 rotates in an unexpected manner. The resulting image will be 1 - // pixel smaller in both dimensions then it would be in PHP 5.4 and what - // math teaches us. Only positive multiples of 90 degrees are rotated as - // one would expect. - if ($arguments['degrees'] < 0) { - $arguments['degrees'] -= floor($arguments['degrees'] / 360) * 360; - } + // 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; return $arguments; } diff --git a/core/modules/system/src/Tests/Image/ToolkitGdTest.php b/core/modules/system/src/Tests/Image/ToolkitGdTest.php index e2c3a31..c966814 100644 --- a/core/modules/system/src/Tests/Image/ToolkitGdTest.php +++ b/core/modules/system/src/Tests/Image/ToolkitGdTest.php @@ -257,11 +257,16 @@ function testManipulations() { $correct_dimensions_real = TRUE; $correct_dimensions_object = TRUE; - // PHP 5.5 rotates in an unexpected manner. The resulting image will be - // 1 pixel smaller in both dimensions then it would be in PHP 5.4 and - // what math teaches us. Only (positive) multiples of 90 degrees are - // rotated as one would expect (but the GD rotate operation already - // converts negative angles to positive ones). + // PHP 5.5 GD bug: https://bugs.php.net/bug.php?id=65148. PHP 5.5 GD + // rotates differently then it did in PHP 5.4 resulting in different + // dimensions then what math teaches us. For the test images, the + // dimensions will be 1 pixel smaller in both dimensions (though other + // tests have shown a difference of 0 to 3 pixels in both dimensions. + // @todo: if and when the PHP bug gets solved, add an upper limit + // version check. + // @todo: in [#1551686] the dimension calculations for rotation are + // reworked. That issue should also check if these tests can be made + // more robust. if (version_compare(PHP_VERSION, '5.5', '>=') && $values['function'] === 'rotate' && $values['arguments']['degrees'] % 90 != 0) { $values['height']--; $values['width']--; @@ -294,16 +299,16 @@ function testManipulations() { $y = 0; break; case 1: - $x = $values['width'] - 1; + $x = $image->getWidth() - 1; $y = 0; break; case 2: - $x = $values['width'] - 1; - $y = $values['height'] - 1; + $x = $image->getWidth() - 1; + $y = $image->getHeight() - 1; break; case 3: $x = 0; - $y = $values['height'] - 1; + $y = $image->getHeight() - 1; break; } $color = $this->getPixelColor($image, $x, $y);