1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-31 09:31:53 +02:00

Restrict the maximum rotation value to 360 degrees

Applying a rotation value more than this may use unnecessary server side resources
This commit is contained in:
Lee Boynton
2018-03-02 17:59:34 +00:00
parent a54d1e9e6a
commit 1ab6b95ca5
3 changed files with 18 additions and 0 deletions

View File

@@ -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()));

View File

@@ -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));

View File

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