We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1c7700e commit 09d512bCopy full SHA for 09d512b
webview-ui/src/utils/image.ts
@@ -0,0 +1,16 @@
1
+/**
2
+ * Utilities for image handling in webview.
3
+ */
4
+export const MAX_IMAGE_BYTES = 10 * 1024 * 1024
5
+
6
7
+ * Estimate raw bytes from a base64 data URL. Returns 0 for invalid input.
8
9
+export function estimateBytesFromBase64DataUrl(dataUrl: string): number {
10
+ if (typeof dataUrl !== "string") return 0
11
+ const idx = dataUrl.indexOf(",")
12
+ if (idx === -1) return 0
13
+ const base64 = dataUrl.slice(idx + 1).replace(/=+$/, "")
14
+ // 4 base64 chars represent 3 bytes
15
+ return Math.floor((base64.length * 3) / 4)
16
+}
0 commit comments