File size: 558 Bytes
624088c
 
 
3b81d2d
624088c
 
 
 
 
3b81d2d
624088c
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { useEffect, useState } from "react"

import { ImageDimension, getImageDimension } from "./getImageDimension"
import { ClapMediaOrientation } from "@aitube/clap"

export function useImageDimension(src: string) {
  const [dimension, setDimension] = useState<ImageDimension>({
    width: 0,
    height: 0,
    orientation: ClapMediaOrientation.SQUARE
  })

  useEffect(() => {
    const compute = async () => {
      const newDimension = await getImageDimension(src)
      setDimension(newDimension)
    }
    compute()
  }, [src])

  return dimension
}