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.
npm install capdimimport capDim from 'capdim';
console.log(capDim([1920, 1080], 1_000_000));
// [1333.3333333333333, 750]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).
Licensed under the MIT License.