Passed
Pull Request — master (#265)
by Pascal
02:53
created

WatermarkFilter::getCommands()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 11
rs 10
1
<?php
2
3
namespace ProtoneMedia\LaravelFFMpeg\Filters;
4
5
use FFMpeg\Filters\Video\WatermarkFilter as FFMpegWatermarkFilter;
6
7
/**
8
 * Partly based on this PR:
9
 * https://github.com/PHP-FFMpeg/PHP-FFMpeg/pull/754/files
10
 */
11
class WatermarkFilter extends FFMpegWatermarkFilter
12
{
13
    protected $path;
14
15
    public function __construct($watermarkPath, array $coordinates = [], $priority = 0)
16
    {
17
        parent::__construct($watermarkPath, $coordinates, $priority);
18
19
        $this->path = $watermarkPath;
20
    }
21
22
    protected function getCommands()
23
    {
24
        $commands = parent::getCommands();
25
26
        $commands[1] = str_replace(
27
            $this->path,
28
            static::normalizePath($this->path),
29
            $commands[1]
30
        );
31
32
        return $commands;
33
    }
34
35
    public static function normalizePath(string $path): string
36
    {
37
        return windows_os() ? static::normalizeWindowsPath($path) : $path;
38
    }
39
40
    public static function normalizeWindowsPath(string $path): string
41
    {
42
        $path = str_replace('/', '\\', $path);
43
        $path = str_replace('\\', '\\\\', $path);
44
        $path = str_replace(':', '\:', $path);
45
46
        return $path;
47
    }
48
}
49