File size: 632 Bytes
99c03ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { ClapImageRatio } from "@aitube/clap"

/**
 * Determine the video imageRatio from a video URL (data-uri or hosted)
 * 
 * @param url 
 * @returns 
 */
export async function getImageRatio(url: string): Promise<ClapImageRatio> {
  return new Promise<ClapImageRatio>(resolve => {
    const video = document.createElement('video')
    video.addEventListener( "loadedmetadata", function () {
      resolve(
        this.videoHeight < this.videoWidth ? ClapImageRatio.LANDSCAPE :
        this.videoHeight > this.videoWidth ? ClapImageRatio.PORTRAIT :
        ClapImageRatio.SQUARE
      )
    }, false)
    video.src = url
  })
}