ai-comic-factory / src /lib /parseLayoutFromStoryboards.ts
jbilcke-hf's picture
jbilcke-hf HF staff
update for oauth
3b81d2d
raw
history blame contribute delete
968 Bytes
import { ClapSegment } from "@aitube/clap"
import { LayoutName } from "@/app/layouts"
import { layouts } from "@/app/layouts/settings"
import { getImageDimension } from "./getImageDimension"
export async function parseLayoutFromStoryboards(storyboards: ClapSegment[]): Promise<LayoutName> {
let bestCandidate: LayoutName = "Layout0"
for (const [layoutName, layoutPanels] of Object.entries(layouts)) {
let nbMatchingStoryboards = 0
let i = 0
for (const { panel, orientation, width, height } of layoutPanels) {
const storyboard = storyboards[i]
if (!storyboard) { continue }
if (!storyboard?.assetUrl) { continue }
const imgDimension = await getImageDimension(storyboard.assetUrl)
if (orientation === imgDimension.orientation) {
nbMatchingStoryboards++
}
i++
}
if (nbMatchingStoryboards === 4) {
bestCandidate = layoutName as LayoutName
}
}
return bestCandidate
}