From 1ab6b95ca5ddb631b624f002d0745465a9e08324 Mon Sep 17 00:00:00 2001 From: Lee Boynton Date: Fri, 2 Mar 2018 17:59:34 +0000 Subject: [PATCH] Restrict the maximum rotation value to 360 degrees Applying a rotation value more than this may use unnecessary server side resources --- src/Intervention/Image/Gd/Commands/RotateCommand.php | 3 +++ .../Image/Imagick/Commands/RotateCommand.php | 3 +++ tests/RotateCommandTest.php | 12 ++++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/Intervention/Image/Gd/Commands/RotateCommand.php b/src/Intervention/Image/Gd/Commands/RotateCommand.php index 26a460db..698f514a 100644 --- a/src/Intervention/Image/Gd/Commands/RotateCommand.php +++ b/src/Intervention/Image/Gd/Commands/RotateCommand.php @@ -18,6 +18,9 @@ class RotateCommand extends \Intervention\Image\Commands\AbstractCommand $color = $this->argument(1)->value(); $color = new Color($color); + // restrict rotations beyond 360 degrees, since the end result is the same + $angle %= 360; + // rotate image $image->setCore(imagerotate($image->getCore(), $angle, $color->getInt())); diff --git a/src/Intervention/Image/Imagick/Commands/RotateCommand.php b/src/Intervention/Image/Imagick/Commands/RotateCommand.php index 3d0eb99c..c4503a6c 100644 --- a/src/Intervention/Image/Imagick/Commands/RotateCommand.php +++ b/src/Intervention/Image/Imagick/Commands/RotateCommand.php @@ -18,6 +18,9 @@ class RotateCommand extends \Intervention\Image\Commands\AbstractCommand $color = $this->argument(1)->value(); $color = new Color($color); + // restrict rotations beyond 360 degrees, since the end result is the same + $angle %= 360; + // rotate image $image->getCore()->rotateImage($color->getPixel(), ($angle * -1)); diff --git a/tests/RotateCommandTest.php b/tests/RotateCommandTest.php index 64f68c99..559b57af 100644 --- a/tests/RotateCommandTest.php +++ b/tests/RotateCommandTest.php @@ -32,4 +32,16 @@ class RotateCommandTest extends PHPUnit_Framework_TestCase $result = $command->execute($image); $this->assertTrue($result); } + + public function testImagickWithLargeRotation() + { + $rotation = 45; + $imagick = Mockery::mock('Imagick'); + $imagick->shouldReceive('rotateimage')->with(Mockery::type('object'), -$rotation)->andReturn(true); + $image = Mockery::mock('Intervention\Image\Image'); + $image->shouldReceive('getCore')->once()->andReturn($imagick); + $command = new RotateImagick([$rotation + (360 * 1000), '#b53717']); + $result = $command->execute($image); + $this->assertTrue($result); + } }