support watermarks
This commit is contained in:
		
							parent
							
								
									47e1153789
								
							
						
					
					
						commit
						3decfae78f
					
				| @ -14,6 +14,11 @@ class ImageEditOptions | |||||||
|      */ |      */ | ||||||
|     private $height; |     private $height; | ||||||
| 
 | 
 | ||||||
|  |     /** | ||||||
|  |      * @var Watermark[][] | ||||||
|  |      */ | ||||||
|  |     private $watermarks = []; | ||||||
|  | 
 | ||||||
|     public function width(int $width) |     public function width(int $width) | ||||||
|     { |     { | ||||||
|         $this->width = $width; |         $this->width = $width; | ||||||
| @ -38,11 +43,48 @@ class ImageEditOptions | |||||||
|         return $this->height; |         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 |     public function toArray(): array | ||||||
|     { |     { | ||||||
|         return array_filter([ |         return array_filter([ | ||||||
|             'width' => $this->width, |             '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 | ||||||
|  |         ]); | ||||||
|  |     } | ||||||
|  | } | ||||||
							
								
								
									
										
											BIN
										
									
								
								testDownloadTo.zip
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								testDownloadTo.zip
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -4,13 +4,14 @@ include __DIR__ . '/../vendor/autoload.php'; | |||||||
| 
 | 
 | ||||||
| use Nwb\MultiDownloaderClient\FileRequest; | use Nwb\MultiDownloaderClient\FileRequest; | ||||||
| use Nwb\MultiDownloaderClient\MultiDownloaderClient; | use Nwb\MultiDownloaderClient\MultiDownloaderClient; | ||||||
|  | use Nwb\MultiDownloaderClient\Watermark; | ||||||
| use PHPUnit\Framework\TestCase; | use PHPUnit\Framework\TestCase; | ||||||
| 
 | 
 | ||||||
| class MultiDownloaderClientTest extends TestCase | class MultiDownloaderClientTest extends TestCase | ||||||
| { | { | ||||||
|     private $testFiles = [ |     private $testFiles = [ | ||||||
|         'https://s3.eu-central-1.wasabisys.com/dev-data-nwb/multi-downloader-sat/tests/img/watermarks/portrait.png', |         'https://dev-data-nwb.s3.eu-central-1.wasabisys.com/multi-downloader-sat/tests/img/source1.jpg', | ||||||
|         '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/Source_portrait_sans_orientation.jpg' | ||||||
|     ]; |     ]; | ||||||
| 
 | 
 | ||||||
|     private function testFiles() |     private function testFiles() | ||||||
| @ -19,6 +20,10 @@ class MultiDownloaderClientTest extends TestCase | |||||||
|             $file = new FileRequest($url); |             $file = new FileRequest($url); | ||||||
|             $file->getFileOptions()->name('test' . $i . '.png'); |             $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; |             return $file; | ||||||
|         }, $this->testFiles, array_keys($this->testFiles)); |         }, $this->testFiles, array_keys($this->testFiles)); | ||||||
|     } |     } | ||||||
| @ -30,7 +35,7 @@ class MultiDownloaderClientTest extends TestCase | |||||||
|         $response = $client->downloadAsString(); |         $response = $client->downloadAsString(); | ||||||
|         $md5 = md5($response); |         $md5 = md5($response); | ||||||
| 
 | 
 | ||||||
|         $this->assertEquals('7542c2c2a0750ab9e62d50bbe83d4c1f', $md5); |         $this->assertEquals('65b11e1e8b2283f769006cec577ee8e0', $md5); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function testDownloadTo() |     public function testDownloadTo() | ||||||
| @ -42,7 +47,7 @@ class MultiDownloaderClientTest extends TestCase | |||||||
|         $md5 = md5_file($path); |         $md5 = md5_file($path); | ||||||
| 
 | 
 | ||||||
|         $this->assertFileExists($path); |         $this->assertFileExists($path); | ||||||
|         $this->assertEquals('7542c2c2a0750ab9e62d50bbe83d4c1f', $md5); |         $this->assertEquals('65b11e1e8b2283f769006cec577ee8e0', $md5); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public function testForm() |     public function testForm() | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user