addressing author requested fixes/changes

This commit is contained in:
Ivan Ganev 2017-11-05 16:28:24 +02:00
commit 8950598211
3 changed files with 6 additions and 2 deletions

View file

@ -108,6 +108,7 @@ class Audio extends AbstractStreamableMedia
* *
* @param integer $width * @param integer $width
* @param integer $height * @param integer $height
* @param array $colors Array of colors for ffmpeg to use. Color format is #000000 (RGB hex string with #)
* @return Waveform * @return Waveform
*/ */
public function waveform($width = 640, $height = 120, $colors = [Waveform::DEFAULT_COLOR]) public function waveform($width = 640, $height = 120, $colors = [Waveform::DEFAULT_COLOR])

View file

@ -79,13 +79,14 @@ class Waveform extends AbstractMediaType
* example #FFFFFF or #000000. By default the color is set to black. Keep in mind that if you save the waveform * example #FFFFFF or #000000. By default the color is set to black. Keep in mind that if you save the waveform
* as jpg file, it will appear completely black and to avoid this you can set the waveform color to white (#FFFFFF). * as jpg file, it will appear completely black and to avoid this you can set the waveform color to white (#FFFFFF).
* Saving waveforms to png is strongly suggested. * Saving waveforms to png is strongly suggested.
*
* @param array $colors * @param array $colors
*/ */
public function setColors(array $colors) public function setColors(array $colors)
{ {
foreach ($colors as $row => $value) foreach ($colors as $row => $value)
{ {
if ($value{0} != '#' || strlen($value) != 7) if (!preg_match_all('/^#(?:[0-9a-fA-F]{6})$/', $value))
{ {
//invalid color //invalid color
unset($colors[$row]); unset($colors[$row]);
@ -102,6 +103,7 @@ class Waveform extends AbstractMediaType
* Returns an array of colors that will be passed to ffmpeg to use for waveform generation. Colors are applied ONLY * Returns an array of colors that will be passed to ffmpeg to use for waveform generation. Colors are applied ONLY
* to the waveform. Background cannot be controlled that easily and it is probably easier to save the waveform * to the waveform. Background cannot be controlled that easily and it is probably easier to save the waveform
* as a transparent png file and then add background of choice. * as a transparent png file and then add background of choice.
*
* @return array * @return array
*/ */
public function getColors() public function getColors()
@ -111,6 +113,7 @@ class Waveform extends AbstractMediaType
/** /**
* Compiles the selected colors into a string, using a pipe separator. * Compiles the selected colors into a string, using a pipe separator.
*
* @return string * @return string
*/ */
protected function compileColors() protected function compileColors()

View file

@ -61,7 +61,7 @@ class WaveformTest extends AbstractMediaTestCase
return array( return array(
array( array(
array( array(
'-i', NULL, '-filter_complex', '-y', '-i', NULL, '-filter_complex',
'showwavespic=colors=#FFFFFF:s=640x120', 'showwavespic=colors=#FFFFFF:s=640x120',
'-frames:v', '1', '-frames:v', '1',
), ),