1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-01 18:02:45 +02:00

Fit & Resize Modifier

This commit is contained in:
Oliver Vogel
2021-11-09 14:17:18 +00:00
parent 585766b4af
commit e168824057
2 changed files with 17 additions and 16 deletions

View File

@@ -12,9 +12,6 @@ use Intervention\Image\Traits\CanResizeGeometrically;
class FitModifier extends ResizeModifier implements ModifierInterface class FitModifier extends ResizeModifier implements ModifierInterface
{ {
use CanResizeGeometrically;
protected $target;
protected $position; protected $position;
public function __construct(SizeInterface $target, string $position = 'top-left') public function __construct(SizeInterface $target, string $position = 'top-left')
@@ -23,18 +20,6 @@ class FitModifier extends ResizeModifier implements ModifierInterface
$this->position = $position; $this->position = $position;
} }
public function apply(ImageInterface $image): ImageInterface
{
$crop = $this->getCropSize($image);
$resize = $this->getResizeSize($image);
foreach ($image as $frame) {
$this->modify($frame, $crop, $resize);
}
return $image;
}
protected function getCropSize(ImageInterface $image): SizeInterface protected function getCropSize(ImageInterface $image): SizeInterface
{ {
$imagesize = $image->getSize(); $imagesize = $image->getSize();

View File

@@ -6,9 +6,12 @@ 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\Interfaces\SizeInterface; use Intervention\Image\Interfaces\SizeInterface;
use Intervention\Image\Traits\CanResizeGeometrically;
class ResizeModifier implements ModifierInterface class ResizeModifier implements ModifierInterface
{ {
use CanResizeGeometrically;
protected $target; protected $target;
public function __construct(SizeInterface $target) public function __construct(SizeInterface $target)
@@ -18,13 +21,26 @@ class ResizeModifier implements ModifierInterface
public function apply(ImageInterface $image): ImageInterface public function apply(ImageInterface $image): ImageInterface
{ {
$crop = $this->getCropSize($image);
$resize = $this->getResizeSize($image);
foreach ($image as $frame) { foreach ($image as $frame) {
$this->modify($frame, $frame->getSize(), $this->target); $this->modify($frame, $crop, $resize);
} }
return $image; return $image;
} }
protected function getCropSize(ImageInterface $image): SizeInterface
{
return $image->getSize();
}
protected function getResizeSize(ImageInterface $image): SizeInterface
{
return $this->target;
}
protected function modify(FrameInterface $frame, SizeInterface $crop, SizeInterface $resize): void protected function modify(FrameInterface $frame, SizeInterface $crop, SizeInterface $resize): void
{ {
// create new image // create new image