1
0
mirror of https://github.com/Intervention/image.git synced 2025-08-29 08:40:33 +02:00

pad & padDown

This commit is contained in:
Oliver Vogel
2021-11-11 14:16:28 +00:00
parent afa86daac4
commit ba7fc0e42e

View File

@@ -211,6 +211,44 @@ abstract class AbstractImage
);
}
public function pad(int $width, int $height, string $position = 'center'): ImageInterface
{
$imagesize = $this->getSize();
// crop
$crop = new Size($width, $height);
$crop = $crop->cover($imagesize)->alignPivotTo(
$imagesize->alignPivot($position),
$position
);
// resize
$resize = $crop->scale($width, $height);
return $this->modify(
$this->resolveDriverClass('Modifiers\CropResizeModifier', $crop, $resize, $position)
);
}
public function padDown(int $width, int $height, string $position = 'center'): ImageInterface
{
$imagesize = $this->getSize();
// crop
$crop = new Size($width, $height);
$crop = $crop->cover($imagesize)->alignPivotTo(
$imagesize->alignPivot($position),
$position
);
// resize
$resize = $crop->scaleDown($width, $height);
return $this->modify(
$this->resolveDriverClass('Modifiers\CropResizeModifier', $crop, $resize, $position)
);
}
public function place($element, string $position = 'top-left', int $offset_x = 0, int $offset_y = 0): ImageInterface
{
return $this->modify(