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

CanhandleInput

This commit is contained in:
Oliver Vogel
2021-11-11 15:33:57 +00:00
parent 4b063ab098
commit e2d032f4f8
3 changed files with 42 additions and 4 deletions

View File

@@ -261,4 +261,11 @@ abstract class AbstractImage
)
);
}
public function rotate(float $angle, $backgroundColor = null): ImageInterface
{
return $this->modify(
$this->resolveDriverClass('Modifiers\RotateModifier', $angle, $backgroundColor)
);
}
}

View File

@@ -5,9 +5,12 @@ namespace Intervention\Image\Drivers\Gd\Modifiers;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\ModifierInterface;
use Intervention\Image\Traits\CanHandleInput;
class RotateModifier implements ModifierInterface
{
use CanHandleInput;
/**
* Rotation angle
*
@@ -20,23 +23,25 @@ class RotateModifier implements ModifierInterface
*
* @var mixed
*/
protected $backgroundcolor;
protected $backgroundColor;
/**
* Create new modifier
*
* @param float $angle
*/
public function __construct(float $angle, $backgroundcolor = null)
public function __construct(float $angle, $backgroundColor = null)
{
$this->angle = $angle;
$this->backgroundcolor = $backgroundcolor;
$this->backgroundColor = $backgroundColor;
}
public function apply(ImageInterface $image): ImageInterface
{
foreach ($image as $frame) {
imagerotate($frame->getCore(), $this->rotationAngle(), 0);
$frame->setCore(
imagerotate($frame->getCore(), $this->rotationAngle(), $this->backgroundColor())
);
}
return $image;
@@ -47,4 +52,14 @@ class RotateModifier implements ModifierInterface
// restrict rotations beyond 360 degrees, since the end result is the same
return fmod($this->angle, 360);
}
protected function backgroundColor(): int
{
$color = $this->handleInput($this->backgroundColor);
echo "<pre>";
var_dump($color);
echo "</pre>";
exit;
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace Intervention\Image\Traits;
use Intervention\Image\Interfaces\ColorInterface;
use Intervention\Image\Interfaces\ImageInterface;
trait CanHandleInput
{
use CanResolveDriverClass;
public function handleInput($input): ImageInterface|ColorInterface
{
return $this->resolveDriverClass('InputHandler')->handle($input);
}
}