Added watermark functionality and unit tests
This commit is contained in:
		
					parent
					
						
							
								8a27b77dcb
							
						
					
				
			
			
				commit
				
					
						475d1a508a
					
				
			
		
					 4 changed files with 157 additions and 0 deletions
				
			
		|  | @ -103,4 +103,17 @@ class VideoFilters extends AudioFilters | |||
| 
 | ||||
|         return $this; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @param string $imagePath | ||||
|      * @param array $coordinates | ||||
|      * | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function watermark($imagePath, array $coordinates = array()) | ||||
|     { | ||||
|         $this->media->addFilter(new WatermarkFilter($imagePath, $coordinates)); | ||||
| 
 | ||||
|         return $this; | ||||
|     } | ||||
| } | ||||
|  |  | |||
							
								
								
									
										81
									
								
								src/FFMpeg/Filters/Video/WatermarkFilter.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								src/FFMpeg/Filters/Video/WatermarkFilter.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,81 @@ | |||
| <?php | ||||
| 
 | ||||
| /* | ||||
|  * This file is part of PHP-FFmpeg. | ||||
|  * | ||||
|  * (c) Alchemy <dev.team@alchemy.fr> | ||||
|  * | ||||
|  * For the full copyright and license information, please view the LICENSE | ||||
|  * file that was distributed with this source code. | ||||
|  */ | ||||
| 
 | ||||
| namespace FFMpeg\Filters\Video; | ||||
| 
 | ||||
| use FFMpeg\Format\VideoInterface; | ||||
| use FFMpeg\Media\Video; | ||||
| use FFMpeg\Coordinate\TimeCode; | ||||
| 
 | ||||
| class WatermarkFilter implements VideoFilterInterface | ||||
| { | ||||
|     /** @var string */ | ||||
|     private $watermarkPath; | ||||
|     /** @var array */ | ||||
|     private $coordinates; | ||||
|     /** @var integer */ | ||||
|     private $priority; | ||||
| 
 | ||||
| 
 | ||||
|     public function __construct($watermarkPath, array $coordinates = array(), $priority = 0) | ||||
|     { | ||||
|         $this->watermarkPath = $watermarkPath; | ||||
|         $this->coordinates = $coordinates; | ||||
|         $this->priority = $priority; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function getPriority() | ||||
|     { | ||||
|         return $this->priority; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * {@inheritdoc} | ||||
|      */ | ||||
|     public function apply(Video $video, VideoInterface $format) | ||||
|     { | ||||
|         $position = isset($this->coordinates['position']) ? $this->coordinates['position'] : 'absolute'; | ||||
| 
 | ||||
|         switch($position) { | ||||
|             case 'relative': | ||||
|                 if (isset($this->coordinates['top'])) { | ||||
|                     $y = $this->coordinates['top']; | ||||
|                 } | ||||
|                 elseif (isset($this->coordinates['bottom'])) { | ||||
|                     $y = sprintf('main_h - %d - overlay_h', $this->coordinates['bottom']); | ||||
|                 } | ||||
|                 else { | ||||
|                     $y = 0; | ||||
|                 } | ||||
| 
 | ||||
|                 if (isset($this->coordinates['left'])) { | ||||
|                     $x = $this->coordinates['left']; | ||||
|                 } | ||||
|                 elseif (isset($this->coordinates['right'])) { | ||||
|                     $x = sprintf('main_w - %d - overlay_w', $this->coordinates['right']); | ||||
|                 } | ||||
|                 else { | ||||
|                     $x = 0; | ||||
|                 } | ||||
| 
 | ||||
|                 break; | ||||
|             default: | ||||
|                 $x = isset($this->coordinates['x']) ? $this->coordinates['x'] : 0; | ||||
|                 $y = isset($this->coordinates['y']) ? $this->coordinates['y'] : 0; | ||||
|                 break; | ||||
|         } | ||||
| 
 | ||||
|         return array('-vf', sprintf('overlay %s:%s', $x, $y)); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue