mirror of
https://github.com/Intervention/image.git
synced 2025-08-21 05:01:20 +02:00
CanhandleInput
This commit is contained in:
@@ -261,4 +261,11 @@ abstract class AbstractImage
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function rotate(float $angle, $backgroundColor = null): ImageInterface
|
||||||
|
{
|
||||||
|
return $this->modify(
|
||||||
|
$this->resolveDriverClass('Modifiers\RotateModifier', $angle, $backgroundColor)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,9 +5,12 @@ namespace Intervention\Image\Drivers\Gd\Modifiers;
|
|||||||
use Intervention\Image\Interfaces\FrameInterface;
|
use Intervention\Image\Interfaces\FrameInterface;
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
|
use Intervention\Image\Traits\CanHandleInput;
|
||||||
|
|
||||||
class RotateModifier implements ModifierInterface
|
class RotateModifier implements ModifierInterface
|
||||||
{
|
{
|
||||||
|
use CanHandleInput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rotation angle
|
* Rotation angle
|
||||||
*
|
*
|
||||||
@@ -20,23 +23,25 @@ class RotateModifier implements ModifierInterface
|
|||||||
*
|
*
|
||||||
* @var mixed
|
* @var mixed
|
||||||
*/
|
*/
|
||||||
protected $backgroundcolor;
|
protected $backgroundColor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new modifier
|
* Create new modifier
|
||||||
*
|
*
|
||||||
* @param float $angle
|
* @param float $angle
|
||||||
*/
|
*/
|
||||||
public function __construct(float $angle, $backgroundcolor = null)
|
public function __construct(float $angle, $backgroundColor = null)
|
||||||
{
|
{
|
||||||
$this->angle = $angle;
|
$this->angle = $angle;
|
||||||
$this->backgroundcolor = $backgroundcolor;
|
$this->backgroundColor = $backgroundColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
foreach ($image as $frame) {
|
foreach ($image as $frame) {
|
||||||
imagerotate($frame->getCore(), $this->rotationAngle(), 0);
|
$frame->setCore(
|
||||||
|
imagerotate($frame->getCore(), $this->rotationAngle(), $this->backgroundColor())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $image;
|
return $image;
|
||||||
@@ -47,4 +52,14 @@ class RotateModifier implements ModifierInterface
|
|||||||
// restrict rotations beyond 360 degrees, since the end result is the same
|
// restrict rotations beyond 360 degrees, since the end result is the same
|
||||||
return fmod($this->angle, 360);
|
return fmod($this->angle, 360);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function backgroundColor(): int
|
||||||
|
{
|
||||||
|
$color = $this->handleInput($this->backgroundColor);
|
||||||
|
|
||||||
|
echo "<pre>";
|
||||||
|
var_dump($color);
|
||||||
|
echo "</pre>";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
16
src/Traits/CanHandleInput.php
Normal file
16
src/Traits/CanHandleInput.php
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user