开发者社区> 镜像站> NPM> bestfit
bestfit
Finds image rendition that best fits a given container.
Last updated 7 years ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install bestfit 
SYNC missed versions from official npm registry.

bestfit build status

testling badge

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);

Output

{ width: 3,
  height: 1.5,
  id: 1,
  widthPercentage: 1.5,
  heightPercentage: 1 }

Installation

npm install bestfit

API

bestfit(renditions) → {function}

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

Note: all renditions are assumed to have the same aspect ratio
Parameters:
Name Type Description
renditions Array.<Object>

available image renditions each having a width and height property

Source:
Returns:

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

Type
function

generated with docme

License

MIT

Current Tags

  • 0.1.5                                ...           latest (7 years ago)

6 Versions

  • 0.1.5                                ...           7 years ago
  • 0.1.4                                ...           7 years ago
  • 0.1.3                                ...           7 years ago
  • 0.1.2                                ...           7 years ago
  • 0.1.1                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (2)
Dependents (0)
None