From d7c7e74c255ff36d69dc7c53c33f1bab982fb842 Mon Sep 17 00:00:00 2001 From: zboyet Date: Tue, 16 Apr 2013 11:18:54 -0700 Subject: [PATCH] Added ability to choose between resolution modulus --- src/FFMpeg/FFMpeg.php | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/src/FFMpeg/FFMpeg.php b/src/FFMpeg/FFMpeg.php index 9caeff3..fd0a4e2 100644 --- a/src/FFMpeg/FFMpeg.php +++ b/src/FFMpeg/FFMpeg.php @@ -332,9 +332,8 @@ class FFMpeg extends Binary if ($originalHeight !== null && $originalWidth !== null) { $dimensions = $format->getComputedDimensions($originalWidth, $originalHeight); - - $width = $this->getMultiple($dimensions->getWidth(), 16); - $height = $this->getMultiple($dimensions->getHeight(), 16); + $width = $this->getMultiple($dimensions->getWidth(), $format->getModulus()); + $height = $this->getMultiple($dimensions->getHeight(), $format->getModulus()); $builder->add('-s')->add($width . 'x' . $height); } @@ -455,31 +454,15 @@ class FFMpeg extends Binary */ protected function getMultiple($value, $multiple) { - $modulo = $value % $multiple; - - $ret = (int) $multiple; - - $halfDistance = $multiple / 2; - if ($modulo <= $halfDistance) - $bound = 'bottom'; - else - $bound = 'top'; - - switch ($bound) { - default: - case 'top': - $ret = $value + $multiple - $modulo; - break; - case 'bottom': - $ret = $value - $modulo; - break; + if (($value % $multiple) === 0){ + return $value; } - if ($ret < $multiple) { - $ret = (int) $multiple; - } + do { + $value++; + } while (($value % $multiple) != 0); - return (int) $ret; + return $value; } /**