1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2025-01-05 11:25:00 +01:00
portfolio/src/components/Vcard/imageToDataUrl.ts

17 lines
406 B
TypeScript
Raw Normal View History

2024-02-05 16:16:18 +01:00
export async function imageToDataUrl(path: string): Promise<string> {
const response = await fetch(path)
const blob = await response.blob()
2024-02-06 02:06:58 +01:00
2024-02-05 16:16:18 +01:00
return new Promise((onSuccess, onError) => {
try {
const reader = new FileReader()
reader.onload = function () {
onSuccess(this.result as string)
}
reader.readAsDataURL(blob)
} catch (e) {
onError(e)
}
})
}