diff --git a/src/ImageEditOptions.php b/src/ImageEditOptions.php index 4263d45..f9501d7 100644 --- a/src/ImageEditOptions.php +++ b/src/ImageEditOptions.php @@ -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), ]); } } diff --git a/src/Watermark.php b/src/Watermark.php new file mode 100644 index 0000000..118ecf2 --- /dev/null +++ b/src/Watermark.php @@ -0,0 +1,91 @@ +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 + ]); + } +} diff --git a/testDownloadTo.zip b/testDownloadTo.zip new file mode 100644 index 0000000..6767252 Binary files /dev/null and b/testDownloadTo.zip differ diff --git a/tests/MultiDownloaderClientTest.php b/tests/MultiDownloaderClientTest.php index 2081182..5196a56 100644 --- a/tests/MultiDownloaderClientTest.php +++ b/tests/MultiDownloaderClientTest.php @@ -4,13 +4,14 @@ include __DIR__ . '/../vendor/autoload.php'; use Nwb\MultiDownloaderClient\FileRequest; use Nwb\MultiDownloaderClient\MultiDownloaderClient; +use Nwb\MultiDownloaderClient\Watermark; use PHPUnit\Framework\TestCase; class MultiDownloaderClientTest extends TestCase { private $testFiles = [ - 'https://s3.eu-central-1.wasabisys.com/dev-data-nwb/multi-downloader-sat/tests/img/watermarks/portrait.png', - 'https://s3.eu-central-1.wasabisys.com/dev-data-nwb/multi-downloader-sat/tests/img/watermarks/paysage.png' + 'https://dev-data-nwb.s3.eu-central-1.wasabisys.com/multi-downloader-sat/tests/img/source1.jpg', + 'https://dev-data-nwb.s3.eu-central-1.wasabisys.com/multi-downloader-sat/tests/img/Source_portrait_sans_orientation.jpg' ]; private function testFiles() @@ -19,6 +20,10 @@ class MultiDownloaderClientTest extends TestCase $file = new FileRequest($url); $file->getFileOptions()->name('test' . $i . '.png'); + $watermark = new Watermark('https://dev-data-nwb.s3.eu-central-1.wasabisys.com/multi-downloader-sat/tests/img/watermarks/watermark.png', 100, 100); + + $file->getImageEditOptions()->addWatermark([$watermark]); + return $file; }, $this->testFiles, array_keys($this->testFiles)); } @@ -30,7 +35,7 @@ class MultiDownloaderClientTest extends TestCase $response = $client->downloadAsString(); $md5 = md5($response); - $this->assertEquals('7542c2c2a0750ab9e62d50bbe83d4c1f', $md5); + $this->assertEquals('65b11e1e8b2283f769006cec577ee8e0', $md5); } public function testDownloadTo() @@ -42,7 +47,7 @@ class MultiDownloaderClientTest extends TestCase $md5 = md5_file($path); $this->assertFileExists($path); - $this->assertEquals('7542c2c2a0750ab9e62d50bbe83d4c1f', $md5); + $this->assertEquals('65b11e1e8b2283f769006cec577ee8e0', $md5); } public function testForm()