scratch – Blame information for rev 115
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
115 | office | 1 | <?php |
2 | |||
3 | /* |
||
4 | * This file is part of PHP-FFmpeg. |
||
5 | * |
||
6 | * (c) Alchemy <dev.team@alchemy.fr> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace FFMpeg\Filters\Video; |
||
13 | |||
14 | use FFMpeg\Exception\InvalidArgumentException; |
||
15 | use FFMpeg\Format\VideoInterface; |
||
16 | use FFMpeg\Media\Video; |
||
17 | |||
18 | class WatermarkFilter implements VideoFilterInterface |
||
19 | { |
||
20 | /** @var string */ |
||
21 | private $watermarkPath; |
||
22 | /** @var array */ |
||
23 | private $coordinates; |
||
24 | /** @var integer */ |
||
25 | private $priority; |
||
26 | |||
27 | public function __construct($watermarkPath, array $coordinates = array(), $priority = 0) |
||
28 | { |
||
29 | if (!file_exists($watermarkPath)) { |
||
30 | throw new InvalidArgumentException(sprintf('File %s does not exist', $watermarkPath)); |
||
31 | } |
||
32 | |||
33 | $this->watermarkPath = $watermarkPath; |
||
34 | $this->coordinates = $coordinates; |
||
35 | $this->priority = $priority; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * {@inheritdoc} |
||
40 | */ |
||
41 | public function getPriority() |
||
42 | { |
||
43 | return $this->priority; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * {@inheritdoc} |
||
48 | */ |
||
49 | public function apply(Video $video, VideoInterface $format) |
||
50 | { |
||
51 | $position = isset($this->coordinates['position']) ? $this->coordinates['position'] : 'absolute'; |
||
52 | |||
53 | switch ($position) { |
||
54 | case 'relative': |
||
55 | if (isset($this->coordinates['top'])) { |
||
56 | $y = $this->coordinates['top']; |
||
57 | } elseif (isset($this->coordinates['bottom'])) { |
||
58 | $y = sprintf('main_h - %d - overlay_h', $this->coordinates['bottom']); |
||
59 | } else { |
||
60 | $y = 0; |
||
61 | } |
||
62 | |||
63 | if (isset($this->coordinates['left'])) { |
||
64 | $x = $this->coordinates['left']; |
||
65 | } elseif (isset($this->coordinates['right'])) { |
||
66 | $x = sprintf('main_w - %d - overlay_w', $this->coordinates['right']); |
||
67 | } else { |
||
68 | $x = 0; |
||
69 | } |
||
70 | |||
71 | break; |
||
72 | default: |
||
73 | $x = isset($this->coordinates['x']) ? $this->coordinates['x'] : 0; |
||
74 | $y = isset($this->coordinates['y']) ? $this->coordinates['y'] : 0; |
||
75 | break; |
||
76 | } |
||
77 | |||
78 | return array('-vf', sprintf('movie=%s [watermark]; [in][watermark] overlay=%s:%s [out]', $this->watermarkPath, $x, $y)); |
||
79 | } |
||
80 | } |