File size: 663 Bytes
5724388
3b81d2d
624088c
 
 
5724388
624088c
 
 
 
5724388
624088c
 
 
 
 
 
3b81d2d
5724388
3b81d2d
5724388
3b81d2d
5724388
3b81d2d
 
624088c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { ClapImageRatio } from "@aitube/clap"

export interface ImageDimension {
  width: number
  height: number
  orientation: ClapImageRatio
}

export async function getImageDimension(src: string): Promise<ImageDimension> {
  if (!src) {
    return { width: 0, height: 0, orientation:  ClapImageRatio.SQUARE }
  }
  const img = new Image()
  img.src = src
  await img.decode()
  const width = img.width
  const height = img.height

  let orientation = ClapImageRatio.SQUARE
  if (width > height) { 
    orientation = ClapImageRatio.LANDSCAPE
  } else if (width < height) {
    orientation = ClapImageRatio.PORTRAIT
  }
  return { width, height, orientation }
}