FacePoke / client /src /lib /convertImageToBase64.ts
jbilcke-hf's picture
jbilcke-hf HF staff
working on improvements
e123fec
raw
history blame
519 Bytes
export async function convertImageToBase64(imageFileOrBlob: File | Blob): Promise<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => {
if (typeof reader.result === 'string') {
resolve(reader.result);
} else {
reject(new Error('Failed to convert image to base64'));
}
};
reader.onerror = () => {
reject(new Error('Error reading file or blob'));
};
reader.readAsDataURL(imageFileOrBlob);
});
}