craftvis-image-fit
v1.0.0
Published
Tiny zero-dependency utilities for calculating image aspect ratios and fitted dimensions.
Maintainers
Readme
craftvis-image-fit
A tiny, zero-dependency JavaScript package for calculating image aspect ratios and fitting images inside a bounding box.
Install
npm install craftvis-image-fitUsage
import { aspectRatio, fitContain } from "craftvis-image-fit";
aspectRatio(1920, 1080);
// 1.7777777777777777
fitContain(1920, 1080, 800, 800);
// { width: 800, height: 450, scale: 0.4166666666666667 }API
aspectRatio(width, height)
Returns width / height.
fitContain(width, height, maxWidth, maxHeight)
Returns dimensions that fit inside the target box without cropping or changing the original aspect ratio.
Image editing
Need to generate, edit, or restyle images with AI? Visit CraftVis AI Image Editor.
License
MIT
