From fe192eb738a31b83b8082d6d222814d1b42999f0 Mon Sep 17 00:00:00 2001 From: Duncan Smart Date: Wed, 22 Oct 2025 01:16:26 +0100 Subject: [PATCH] compressImage: preserve image type Previously always exported as PNG, causing JPEG images to balloon 3-10x in size with considerable implications for front-end performance (UI gets sluggish e.g. https://github.com/open-webui/open-webui/discussions/11941) --- src/lib/utils/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index f4818f340a..ca3f323e17 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -348,7 +348,8 @@ export const compressImage = async (imageUrl, maxWidth, maxHeight) => { context.drawImage(img, 0, 0, width, height); // Get compressed image URL - const compressedUrl = canvas.toDataURL(); + const mimeType = imageUrl.match(/^data:([^;]+);/)?.[1]; + const compressedUrl = canvas.toDataURL(mimeType); resolve(compressedUrl); }; img.onerror = (error) => reject(error);