export aspect ratio

This commit is contained in:
Siddharth
2025-11-29 11:38:09 -07:00
parent d2ee511466
commit 0c89e3e01a
5 changed files with 124 additions and 89 deletions
+12 -26
View File
@@ -1,29 +1,15 @@
export type AspectRatio = '16:9' | '9:16' | '1:1' | '4:3';
export type AspectRatio = '16:9' | '9:16' | '1:1' | '4:3' | '4:5';
/**
* Converts aspect ratio string to numeric value
* @param aspectRatio - Aspect ratio as string (e.g., '16:9')
* @returns Numeric aspect ratio value (e.g., 1.777... for 16:9)
*/
export function getAspectRatioValue(aspectRatio: AspectRatio): number {
switch (aspectRatio) {
case '16:9':
return 16 / 9;
case '9:16':
return 9 / 16;
case '1:1':
return 1;
case '4:3':
return 4 / 3;
case '16:9': return 16 / 9;
case '9:16': return 9 / 16;
case '1:1': return 1;
case '4:3': return 4 / 3;
case '4:5': return 4 / 5;
}
}
/**
* Calculates dimensions for a given aspect ratio based on a base width
* @param aspectRatio - Aspect ratio as string
* @param baseWidth - Base width to calculate from
* @returns Object with width and height
*/
export function getAspectRatioDimensions(
aspectRatio: AspectRatio,
baseWidth: number
@@ -35,11 +21,11 @@ export function getAspectRatioDimensions(
};
}
/**
* Formats aspect ratio for CSS
* @param aspectRatio - Aspect ratio as string
* @returns CSS-compatible aspect ratio string
*/
export function getAspectRatioLabel(aspectRatio: AspectRatio): string {
return aspectRatio;
}
export function formatAspectRatioForCSS(aspectRatio: AspectRatio): string {
return aspectRatio.replace(':', '/');
}
}