blob: 23fc4f4668159effa792b14a23ecbd8a05d0663f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
export function dimensionToAspectRatio({
width,
height,
}: {
width: number;
height: number;
}): string {
const gcd = (a: number, b: number): number => (b === 0 ? a : gcd(b, a % b));
const divisor = gcd(width, height);
const aspectWidth = width / divisor;
const aspectHeight = height / divisor;
return `${aspectWidth}:${aspectHeight}`;
}
|