mirror of
https://github.com/Intervention/image.git
synced 2025-08-21 05:01:20 +02:00
Refactor code
This commit is contained in:
@@ -2,15 +2,14 @@
|
|||||||
|
|
||||||
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
namespace Intervention\Image\Drivers\Gd\Modifiers;
|
||||||
|
|
||||||
use Intervention\Image\Drivers\Gd\Image;
|
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
use Intervention\Image\Interfaces\PointInterface;
|
use Intervention\Image\Interfaces\PointInterface;
|
||||||
use Intervention\Image\Traits\CanResolveDriverClass;
|
use Intervention\Image\Traits\CanHandleInput;
|
||||||
|
|
||||||
class PlaceModifier implements ModifierInterface
|
class PlaceModifier implements ModifierInterface
|
||||||
{
|
{
|
||||||
use CanResolveDriverClass;
|
use CanHandleInput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new modifier
|
* Create new modifier
|
||||||
@@ -27,7 +26,7 @@ class PlaceModifier implements ModifierInterface
|
|||||||
|
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
$watermark = $this->decodeWatermark();
|
$watermark = $this->handleInput($this->element);
|
||||||
$position = $this->getPosition($image, $watermark);
|
$position = $this->getPosition($image, $watermark);
|
||||||
|
|
||||||
foreach ($image as $frame) {
|
foreach ($image as $frame) {
|
||||||
@@ -47,11 +46,6 @@ class PlaceModifier implements ModifierInterface
|
|||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function decodeWatermark(): Image
|
|
||||||
{
|
|
||||||
return $this->resolveDriverClass('InputHandler')->handle($this->element);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getPosition(ImageInterface $image, ImageInterface $watermark): PointInterface
|
protected function getPosition(ImageInterface $image, ImageInterface $watermark): PointInterface
|
||||||
{
|
{
|
||||||
$image_size = $image->getSize()->movePivot($this->position, $this->offset_x, $this->offset_y);
|
$image_size = $image->getSize()->movePivot($this->position, $this->offset_x, $this->offset_y);
|
||||||
|
@@ -4,15 +4,14 @@ namespace Intervention\Image\Drivers\Imagick\Modifiers;
|
|||||||
|
|
||||||
use Imagick;
|
use Imagick;
|
||||||
use Intervention\Image\Drivers\Imagick\Image;
|
use Intervention\Image\Drivers\Imagick\Image;
|
||||||
use Intervention\Image\Geometry\Point;
|
|
||||||
use Intervention\Image\Interfaces\ImageInterface;
|
use Intervention\Image\Interfaces\ImageInterface;
|
||||||
use Intervention\Image\Interfaces\ModifierInterface;
|
use Intervention\Image\Interfaces\ModifierInterface;
|
||||||
use Intervention\Image\Interfaces\PointInterface;
|
use Intervention\Image\Interfaces\PointInterface;
|
||||||
use Intervention\Image\Traits\CanResolveDriverClass;
|
use Intervention\Image\Traits\CanHandleInput;
|
||||||
|
|
||||||
class PlaceModifier implements ModifierInterface
|
class PlaceModifier implements ModifierInterface
|
||||||
{
|
{
|
||||||
use CanResolveDriverClass;
|
use CanHandleInput;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected $element,
|
protected $element,
|
||||||
@@ -25,7 +24,7 @@ class PlaceModifier implements ModifierInterface
|
|||||||
|
|
||||||
public function apply(ImageInterface $image): ImageInterface
|
public function apply(ImageInterface $image): ImageInterface
|
||||||
{
|
{
|
||||||
$watermark = $this->decodeWatermark();
|
$watermark = $this->handleInput($this->element);
|
||||||
$position = $this->getPosition($image, $watermark);
|
$position = $this->getPosition($image, $watermark);
|
||||||
|
|
||||||
foreach ($image as $frame) {
|
foreach ($image as $frame) {
|
||||||
@@ -40,11 +39,6 @@ class PlaceModifier implements ModifierInterface
|
|||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function decodeWatermark(): Image
|
|
||||||
{
|
|
||||||
return $this->resolveDriverClass('InputHandler')->handle($this->element);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getPosition(ImageInterface $image, Image $watermark): PointInterface
|
protected function getPosition(ImageInterface $image, Image $watermark): PointInterface
|
||||||
{
|
{
|
||||||
$image_size = $image->getSize()->movePivot($this->position, $this->offset_x, $this->offset_y);
|
$image_size = $image->getSize()->movePivot($this->position, $this->offset_x, $this->offset_y);
|
||||||
|
Reference in New Issue
Block a user