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)
This commit is contained in:
Duncan Smart 2025-10-22 01:16:26 +01:00 committed by GitHub
parent 7a83e7dfa3
commit fe192eb738
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);