Added ability to choose between resolution modulus

This commit is contained in:
zboyet 2013-04-16 11:18:54 -07:00
commit d7c7e74c25

View file

@ -332,9 +332,8 @@ class FFMpeg extends Binary
if ($originalHeight !== null && $originalWidth !== null) { if ($originalHeight !== null && $originalWidth !== null) {
$dimensions = $format->getComputedDimensions($originalWidth, $originalHeight); $dimensions = $format->getComputedDimensions($originalWidth, $originalHeight);
$width = $this->getMultiple($dimensions->getWidth(), $format->getModulus());
$width = $this->getMultiple($dimensions->getWidth(), 16); $height = $this->getMultiple($dimensions->getHeight(), $format->getModulus());
$height = $this->getMultiple($dimensions->getHeight(), 16);
$builder->add('-s')->add($width . 'x' . $height); $builder->add('-s')->add($width . 'x' . $height);
} }
@ -455,31 +454,15 @@ class FFMpeg extends Binary
*/ */
protected function getMultiple($value, $multiple) protected function getMultiple($value, $multiple)
{ {
$modulo = $value % $multiple; if (($value % $multiple) === 0){
return $value;
$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 ($ret < $multiple) { do {
$ret = (int) $multiple; $value++;
} } while (($value % $multiple) != 0);
return (int) $ret; return $value;
} }
/** /**