support watermarks
This commit is contained in:
@@ -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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
91
src/Watermark.php
Normal file
91
src/Watermark.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Nwb\MultiDownloaderClient;
|
||||
|
||||
class Watermark
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $url;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $fallbackUrl;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $width;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $height;
|
||||
|
||||
public function __construct(string $url, int $width, int $height)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->width = $width;
|
||||
$this->height = $height;
|
||||
}
|
||||
|
||||
public function url(string $url)
|
||||
{
|
||||
$this->url = $url;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getUrl(): string
|
||||
{
|
||||
return $this->url;
|
||||
}
|
||||
|
||||
public function fallbackUrl(string $fallbackUrl)
|
||||
{
|
||||
$this->fallbackUrl = $fallbackUrl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFallbackUrl(): string
|
||||
{
|
||||
return $this->fallbackUrl;
|
||||
}
|
||||
|
||||
public function width(int $width)
|
||||
{
|
||||
$this->width = $width;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWidth(): int
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
public function height(int $height)
|
||||
{
|
||||
$this->height = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHeight(): int
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return array_filter([
|
||||
'url' => $this->url,
|
||||
'fallbackUrl' => $this->fallbackUrl,
|
||||
'width' => $this->width,
|
||||
'height' => $this->height
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user