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

RotateModifier

This commit is contained in:
Oliver Vogel
2021-11-11 15:21:50 +00:00
parent 385e58ca7d
commit 4b063ab098

View File

@@ -0,0 +1,50 @@
<?php
namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface;
class RotateModifier implements ModifierInterface
{
/**
* Rotation angle
*
* @var float
*/
protected $angle;
/**
* Background color
*
* @var mixed
*/
protected $backgroundcolor;
/**
* Create new modifier
*
* @param float $angle
*/
public function __construct(float $angle, $backgroundcolor = null)
{
$this->angle = $angle;
$this->backgroundcolor = $backgroundcolor;
}
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
imagerotate($frame->getCore(), $this->rotationAngle(), 0);
}
return $image;
}
protected function rotationAngle(): float
{
// restrict rotations beyond 360 degrees, since the end result is the same
return fmod($this->angle, 360);
}
}