aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/Utils.ts')
-rw-r--r--src/Utils.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/Utils.ts b/src/Utils.ts
index 38325a463..0353a2ff7 100644
--- a/src/Utils.ts
+++ b/src/Utils.ts
@@ -925,3 +925,21 @@ export function dateRangeStrToDates(dateStr: string) {
return [new Date(fromYear, fromMonth, fromDay), new Date(toYear, toMonth, toDay)];
}
+
+export async function convertImageToBase64(url: string): Promise<string> {
+ try {
+ const response = await fetch(url); // Fetch the image
+ if (!response.ok) throw new Error('Network response was not ok');
+ const blob = await response.blob(); // Convert response to Blob
+
+ return new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ reader.readAsDataURL(blob); // Read blob as DataURL (Base64)
+ reader.onloadend = () => resolve(reader.result as string); // Resolve promise with Base64 string
+ reader.onerror = error => reject(error); // Reject promise on error
+ });
+ } catch (error) {
+ console.error('Error:', error);
+ throw error; // Rethrow the error after logging it
+ }
+}