mirror of
https://github.com/kremalicious/portfolio.git
synced 2025-01-03 18:35:00 +01:00
17 lines
406 B
TypeScript
17 lines
406 B
TypeScript
export async function imageToDataUrl(path: string): Promise<string> {
|
|
const response = await fetch(path)
|
|
const blob = await response.blob()
|
|
|
|
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)
|
|
}
|
|
})
|
|
}
|