1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-01 09:52:59 +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
{
use CanResizeGeometrically;
protected $target;
protected $position;
public function __construct(SizeInterface $target, string $position = 'top-left')
@@ -23,18 +20,6 @@ class FitModifier extends ResizeModifier implements ModifierInterface
$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
{
$imagesize = $image->getSize();

View File

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