capdim
v1.0.3
Published
Caps an N-dimensional array to a maximum total volume (the product of its dimensions) while preserving proportions.
Downloads
13
Maintainers
Readme
capdim
Canonical URL:
https://alexstevovich.com/a/capdim-nodejs
Software URL:
https://midnightcitylights.com/software/capdim-nodejs
Caps an N-dimensional array to a maximum total volume (the product of its dimensions) while preserving proportions. Useful for image processing workflows and more.
Installation
npm install capdimExample
import capDim from 'capdim';
console.log(capDim([1920, 1080], 1_000_000));
// [1333.3333333333333, 750]🔧 API
capDim(dims: number[], maxVolume: number): number[]
Caps the input dimensions so that their total product does not exceed maxVolume.
dims– Array of dimensions (e.g.,[width, height, depth]).maxVolume– The maximum allowed product of dimensions.Returns: The new scaled-down dimensions (or the original if already within bounds).
License
Licensed under the MIT License.
