-
Notifications
You must be signed in to change notification settings - Fork 12
/
thumbnailer.php
executable file
·83 lines (71 loc) · 1.87 KB
/
thumbnailer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/php
<?php
/**
*
*
* Place the following code in the file `/usr/share/thumbnailers/waveform.thumbnailer`
* ```
* [Thumbnailer Entry]
* Exec=/path/to/this/thumbnailer.php %i %o %sx%s
* MimeType=audio/wave;audio/x-wav;audio/mpeg;audio/ogg
* ```
*
* @author MaximAL
* @since 2016-11-21
* @date 2016-11-21
* @time 19:08
* @link http://maximals.ru
* @link http://sijeko.ru
* @link https://github.com/maximal/audio-waveform-php
* @copyright © MaximAL, Sijeko 2016
*/
namespace maximal\audio;
require_once __DIR__ . '/Waveform.php';
// Default image size
$width = 512;
$height = 512;
// Audio and thumbnail files are required
if (count($argv) < 3) {
echo 'Error: audio and thumbnail files not specified!', PHP_EOL;
echo 'Usage: php ', $argv[0],
' <audio file> <thumbnail file> [<thumbnail size in pixels, default is ',
$width, '×', $height, '>] [two-phase|positive, default is `two-phase`]',
PHP_EOL;
exit(1);
}
$filename = $argv[1];
$thumbnail = $argv[2];
// Parsing the size of waveform image
if (count($argv) > 3) {
$match = null;
if (preg_match('/(\d+)[x×](\d+)/ui', $argv[3], $match)) {
$width = intval($match[1]);
$height = intval($match[2]);
} else {
$width = $height = 0;
}
if ($width === 0 || $height === 0) {
echo 'Error: «', $argv[3], '» size not valid!', PHP_EOL,
'Use the form of «width×height». For example: 256x256, 512×256, etc.', PHP_EOL;
exit(2);
}
}
// Parsing phase setting
$onePhase = false;
if (count($argv) > 4) {
if (strtolower($argv[4]) === 'positive') {
$onePhase = true;
}
}
if (!is_file($filename)) {
echo 'Error: file «', $filename, '» not found!', PHP_EOL;
exit(3);
}
$waveform = new Waveform($filename);
// Some settings
//Waveform::$color = [255, 0, 0, 0.5];
//Waveform::$backgroundColor = [0, 0, 0, 0];
if (!$waveform->getWaveform($thumbnail, $width, $height, $onePhase)) {
exit(4);
}
exit(0);