lib/options/videosize.js
function createSizeFilters(output, key, value) {
  // Store parameters
  var data = output.sizeData = output.sizeData || {};
  data[key] = value;

  if (!('size' in data)) {
    // No size requested, keep original size
    return [];
  }

  // Try to match the different size string formats
  var fixedSize = data.size.match(/([0-9]+)x([0-9]+)/);
  var fixedWidth = data.size.match(/([0-9]+)x\?/);
  var fixedHeight = data.size.match(/\?x([0-9]+)/);
  var percentRatio = data.size.match(/\b([0-9]{1,3})%/);
  var width, height, aspect;

  if (percentRatio) {
    var ratio = Number(percentRatio[1]) / 100;
    return [{
      filter: 'scale',
      options: {
        w: 'trunc(iw*' + ratio + '/2)*2',
        h: 'trunc(ih*' + ratio + '/2)*2'
      }
    }];
  } else if (fixedSize) {
    // Round target size to multiples of 2
    width = Math.round(Number(fixedSize[1]) / 2) * 2;
    height = Math.round(Number(fixedSize[2]) / 2) * 2;

    aspect = width / height;

    if (data.pad) {
      return getScalePadFilters(width, height, aspect, data.pad);
    } else {
      // No autopad requested, rescale to target size
      return [{ filter: 'scale', options: { w: width, h: height }}];
    }
  } else if (fixedWidth || fixedHeight) {
    if ('aspect' in data) {
      // Specified aspect ratio
      width = fixedWidth ? fixedWidth[1] : Math.round(Number(fixedHeight[1]) * data.aspect);
      height = fixedHeight ? fixedHeight[1] : Math.round(Number(fixedWidth[1]) / data.aspect);

      // Round to multiples of 2
      width = Math.round(width / 2) * 2;
      height = Math.round(height / 2) * 2;

      if (data.pad) {
        return getScalePadFilters(width, height, data.aspect, data.pad);
      } else {
        // No autopad requested, rescale to target size
        return [{ filter: 'scale', options: { w: width, h: height }}];
      }
    } else {
      // Keep input aspect ratio

      if (fixedWidth) {
        return [{
          filter: 'scale',
          options: {
            w: Math.round(Number(fixedWidth[1]) / 2) * 2,
            h: 'trunc(ow/a/2)*2'
          }
        }];
      } else {
        return [{
          filter: 'scale',
          options: {
            w: 'trunc(oh*a/2)*2',
            h: Math.round(Number(fixedHeight[1]) / 2) * 2
          }
        }];
      }
    }
  } else {
    throw new Error('Invalid size specified: ' + data.size);
  }
}
function createSizeFilters(output, key, value) {
  // Store parameters
  var data = output.sizeData = output.sizeData || {};
  data[key] = value;

  if (!('size' in data)) {
    // No size requested, keep original size
    return [];
  }

  // Try to match the different size string formats
  var fixedSize = data.size.match(/([0-9]+)x([0-9]+)/);
  var fixedWidth = data.size.match(/([0-9]+)x\?/);
  var fixedHeight = data.size.match(/\?x([0-9]+)/);
  var percentRatio = data.size.match(/\b([0-9]{1,3})%/);
  var width, height, aspect;

  if (percentRatio) {
    var ratio = Number(percentRatio[1]) / 100;
    return [{
      filter: 'scale',
      options: {
        w: 'trunc(iw*' + ratio + '/2)*2',
        h: 'trunc(ih*' + ratio + '/2)*2'
      }
    }];
  } else if (fixedSize) {
    // Round target size to multiples of 2
    width = Math.round(Number(fixedSize[1]) / 2) * 2;
    height = Math.round(Number(fixedSize[2]) / 2) * 2;

    aspect = width / height;

    if (data.pad) {
      return getScalePadFilters(width, height, aspect, data.pad);
    } else {
      // No autopad requested, rescale to target size
      return [{ filter: 'scale', options: { w: width, h: height }}];
    }
  } else if (fixedWidth || fixedHeight) {
    if ('aspect' in data) {
      // Specified aspect ratio
      width = fixedWidth ? fixedWidth[1] : Math.round(Number(fixedHeight[1]) * data.aspect);
      height = fixedHeight ? fixedHeight[1] : Math.round(Number(fixedWidth[1]) / data.aspect);

      // Round to multiples of 2
      width = Math.round(width / 2) * 2;
      height = Math.round(height / 2) * 2;

      if (data.pad) {
        return getScalePadFilters(width, height, data.aspect, data.pad);
      } else {
        // No autopad requested, rescale to target size
        return [{ filter: 'scale', options: { w: width, h: height }}];
      }
    } else {
      // Keep input aspect ratio

      if (fixedWidth) {
        return [{
          filter: 'scale',
          options: {
            w: Math.round(Number(fixedWidth[1]) / 2) * 2,
            h: 'trunc(ow/a/2)*2'
          }
        }];
      } else {
        return [{
          filter: 'scale',
          options: {
            w: 'trunc(oh*a/2)*2',
            h: Math.round(Number(fixedHeight[1]) / 2) * 2
          }
        }];
      }
    }
  } else {
    throw new Error('Invalid size specified: ' + data.size);
  }
}
function createSizeFilters ( output , key , value ) { // Store parameters var data = output . sizeData = output . sizeData || { } ; data [ key ] = value ; if ( ! ( 'size' in data ) ) { // No size requested, keep original size return [ ] ; } // Try to match the different size string formats var fixedSize = data . size . match ( / ([0-9]+)x([0-9]+) / ) ; var fixedWidth = data . size . match ( / ([0-9]+)x\? / ) ; var fixedHeight = data . size . match ( / \?x([0-9]+) / ) ; var percentRatio = data . size . match ( / \b([0-9]{1,3})% / ) ; var width , height , aspect ; if ( percentRatio ) { var ratio = Number ( percentRatio [ 1 ] ) / 100 ; return [ { filter : 'scale' , options : { w : 'trunc(iw*' + ratio + '/2)*2' , h : 'trunc(ih*' + ratio + '/2)*2' } } ] ; } else if ( fixedSize ) { // Round target size to multiples of 2 width = Math . round ( Number ( fixedSize [ 1 ] ) / 2 ) * 2 ; height = Math . round ( Number ( fixedSize [ 2 ] ) / 2 ) * 2 ; aspect = width / height ; if ( data . pad ) { return getScalePadFilters ( width , height , aspect , data . pad ) ; } else { // No autopad requested, rescale to target size return [ { filter : 'scale' , options : { w : width , h : height } } ] ; } } else if ( fixedWidth || fixedHeight ) { if ( 'aspect' in data ) { // Specified aspect ratio width = fixedWidth ? fixedWidth [ 1 ] : Math . round ( Number ( fixedHeight [ 1 ] ) * data . aspect ) ; height = fixedHeight ? fixedHeight [ 1 ] : Math . round ( Number ( fixedWidth [ 1 ] ) / data . aspect ) ; // Round to multiples of 2 width = Math . round ( width / 2 ) * 2 ; height = Math . round ( height / 2 ) * 2 ; if ( data . pad ) { return getScalePadFilters ( width , height , data . aspect , data . pad ) ; } else { // No autopad requested, rescale to target size return [ { filter : 'scale' , options : { w : width , h : height } } ] ; } } else { // Keep input aspect ratio if ( fixedWidth ) { return [ { filter : 'scale' , options : { w : Math . round ( Number ( fixedWidth [ 1 ] ) / 2 ) * 2 , h : 'trunc(ow/a/2)*2' } } ] ; } else { return [ { filter : 'scale' , options : { w : 'trunc(oh*a/2)*2' , h : Math . round ( Number ( fixedHeight [ 1 ] ) / 2 ) * 2 } } ] ; } } } else { throw new Error ( 'Invalid size specified: ' + data . size ) ; } }
Recompute size filters

@param {Object} output
@param {String} key newly-added parameter name ('size', 'aspect' or 'pad')
@param {String} value newly-added parameter value
@return filter string array
@private
Recompute size filters