bestfit

Finds image rendition that best fits a given container.

bestfit

Finds image rendition that best fits a given container.

var bestfit = require('bestfit');
 
var renditions = [
  { width: 2 ,height: 1, id: 0 }
, { width: 3 ,height: 1.5, id: 1 }
, { width: 1 ,height: 0.5, id: 2 }
, { width: 4 ,height: 2, id: 3 }
];
 
var fn = bestfit(renditions);
fn(2, 1.5);
{ width: 3,
  height: 1.5,
  id: 1,
  widthPercentage: 1.5,
  heightPercentage: 1 }
npm install bestfit

Finds image rendition that best fits a given container preferring images that are too large over images that are too small.

Name Type Description
renditions Array.<Object>

available image renditions each having a width and height property

Source:

when called with available width and height it returns the best fitting rendition

Type function

generated with docme

MIT