21 lines
474 B
TypeScript
21 lines
474 B
TypeScript
export const getLocalImageSize = (file: File) =>
|
|
new Promise<{ width: number; height: number }>((resolve) => {
|
|
const reader = new FileReader()
|
|
|
|
reader.onload = function (e: any) {
|
|
const data = e.target.result
|
|
const image = new Image()
|
|
|
|
image.onload = function () {
|
|
const width = image.width
|
|
const height = image.height
|
|
|
|
resolve({ width, height })
|
|
}
|
|
|
|
image.src = data
|
|
}
|
|
|
|
reader.readAsDataURL(file)
|
|
})
|