Skip to content

alexstevovich/capdim-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 capdim

Example

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published