support watermarks

This commit is contained in:
2024-03-18 12:38:14 +00:00
parent 47e1153789
commit 3decfae78f
4 changed files with 143 additions and 5 deletions

View File

@@ -14,6 +14,11 @@ class ImageEditOptions
*/
private $height;
/**
* @var Watermark[][]
*/
private $watermarks = [];
public function width(int $width)
{
$this->width = $width;
@@ -38,11 +43,48 @@ class ImageEditOptions
return $this->height;
}
public function watermarks(array $watermarks)
{
$this->watermarks = [];
$this->addWatermarks($watermarks);
return $this;
}
/**
* @param array $declinations Tableau de déclinaisons d'une watermark dans plusieurs tailles
*/
public function addWatermark(array $declinations)
{
$this->watermarks[] = $declinations;
return $this;
}
public function addWatermarks(array $watermarks)
{
foreach ($watermarks as $watermark) {
$this->addWatermark($watermark);
}
return $this;
}
public function getWatermarks(): array
{
return $this->watermarks;
}
public function toArray(): array
{
return array_filter([
'width' => $this->width,
'height' => $this->height
'height' => $this->height,
'watermarks' => array_map(function (array $declinations) {
return array_map(function (Watermark $watermark) {
return $watermark->toArray();
}, $declinations);
}, $this->watermarks),
]);
}
}