File size: 348 Bytes
624088c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
export interface ImageDimension {
  width: number
  height: number
}

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