Support previewing animated image uploads (#3479)

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Christian Byrne
2025-04-17 22:20:09 +08:00
committed by GitHub
parent f1a25989d7
commit 87bf2310b6
16 changed files with 232 additions and 14 deletions

View File

@@ -10,3 +10,20 @@ export const is_all_same_aspect_ratio = (imgs: HTMLImageElement[]): boolean => {
return true
}
export const fitDimensionsToNodeWidth = (
width: number,
height: number,
nodeWidth: number,
minHeight: number = 64
): { minHeight: number; minWidth: number } => {
const intrinsicAspectRatio = width / height
if (!intrinsicAspectRatio || isNaN(intrinsicAspectRatio))
return { minHeight: 0, minWidth: 0 }
// Set min. height s.t. image spans node's x-axis while maintaining aspect ratio
const minWidth = nodeWidth
const calculatedHeight = Math.max(minWidth / intrinsicAspectRatio, minHeight)
return { minHeight: calculatedHeight, minWidth }
}