1
0
mirror of https://github.com/Intervention/image.git synced 2025-01-17 12:18:14 +01:00
This commit is contained in:
Oliver Vogel 2023-12-07 15:55:09 +01:00
parent 59a4353661
commit 2fe03aeba7
6 changed files with 43 additions and 10 deletions

View File

@ -537,11 +537,16 @@ final class Image implements ImageInterface, Countable
return $this->modify(new ResizeCanvasModifier($width, $height, $background, $position));
}
/**
* {@inheritdoc}
*
* @see ImageInterface::resizeCanvasRelative()
*/
public function resizeCanvasRelative(
?int $width = null,
?int $height = null,
mixed $background = 'ffffff',
string $position = 'center',
string $position = 'center'
): ImageInterface {
return $this->modify(new ResizeCanvasRelativeModifier($width, $height, $background, $position));
}

View File

@ -403,7 +403,7 @@ interface ImageInterface extends IteratorAggregate, Countable
int $width,
int $height,
mixed $background = 'ffffff',
string $position = 'center',
string $position = 'center'
): ImageInterface;
/**
@ -420,7 +420,7 @@ interface ImageInterface extends IteratorAggregate, Countable
int $width,
int $height,
mixed $background = 'ffffff',
string $position = 'center',
string $position = 'center'
): ImageInterface;
/**
@ -440,7 +440,7 @@ interface ImageInterface extends IteratorAggregate, Countable
int $height,
int $offset_x = 0,
int $offset_y = 0,
string $position = 'top-left',
string $position = 'top-left'
): ImageInterface;
/**

View File

@ -19,12 +19,28 @@ class ContainModifier extends AbstractModifier
public function getCropSize(ImageInterface $image): SizeInterface
{
return $image->size()
->contain($this->width, $this->height)
->alignPivotTo($this->getResizeSize($image), $this->position);
->contain(
$this->width,
$this->height
)
->alignPivotTo(
$this->getResizeSize($image),
$this->position()
);
}
public function getResizeSize(ImageInterface $image): SizeInterface
{
return new Rectangle($this->width, $this->height);
}
protected function position(): string
{
return strtr($this->position, [
'left' => 'right',
'right' => 'left',
'top' => 'bottom',
'bottom' => 'top',
]);
}
}

View File

@ -10,7 +10,13 @@ class PadModifier extends ContainModifier
public function getCropSize(ImageInterface $image): SizeInterface
{
return $image->size()
->containMax($this->width, $this->height)
->alignPivotTo($this->getResizeSize($image), $this->position);
->containMax(
$this->width,
$this->height
)
->alignPivotTo(
$this->getResizeSize($image),
$this->position()
);
}
}

View File

@ -22,7 +22,10 @@ class ResizeCanvasModifier extends AbstractModifier
$height = is_null($this->height) ? $image->height() : $this->height;
return (new Rectangle($width, $height))
->alignPivotTo($image->size(), $this->position());
->alignPivotTo(
$image->size(),
$this->position()
);
}
protected function position(): string

View File

@ -14,6 +14,9 @@ class ResizeCanvasRelativeModifier extends ResizeCanvasModifier
$height = is_null($this->height) ? $image->height() : $image->height() + $this->height;
return (new Rectangle($width, $height))
->alignPivotTo($image->size(), $this->position());
->alignPivotTo(
$image->size(),
$this->position()
);
}
}