Aspect Ratio Calculator
Calculate aspect ratio. Supports calculating width, height or the aspect ratio value.
About
Aspect Ratio Calculate runs various calculations to dynamically
calculate
and width
or height
and ratioWidth
.ratioHeight
gcd()
Greatest Common Divisor (GCD) is the highest number that is evenly divisible by both numbers.
const gcd = (a: number, b: number): number => (b == 0 ? a : gcd(b, a % b))
closestAspectRatio()
function closestAspectRatio(width: number, height: number) {
const _gcd = gcd(width, height)
const ratioWidth = width / _gcd
const ratioHeight = height / _gcd
const decimal = ratioWidth / ratioHeight
return {
ratioWidth,
ratioHeight,
decimal,
}
}
This method calculates the closest aspect ratio given the
and height
values. It is used when
either width
or height
are adjusted.width
width
when changed, adjusts the
and
ratioHeight
values using the above
ratioHeight
method.closestAspectRatio()
const {
ratioWidth,
ratioHeight
} = closestAspectRatio(newWidthValue, height)
height
when changed, adjusts the
and
ratioHeight
values using the above
ratioHeight
method.closestAspectRatio()
const {
ratioWidth,
ratioHeight
} = closestAspectRatio(width, newHeightValue)
ratioWidth
when changed, adjusts the
value.width
const width = (height * newRatioWidthValue) / ratioHeight
ratioHeight
when changed, adjusts the
value.height
const height = (width * newRatioHeightValue) / ratioWidth