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:
@@ -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();
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user