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

View File

@@ -348,7 +348,8 @@ export const compressImage = async (imageUrl, maxWidth, maxHeight) => {
context.drawImage(img, 0, 0, width, height); context.drawImage(img, 0, 0, width, height);
// Get compressed image URL // Get compressed image URL
const compressedUrl = canvas.toDataURL(); const mimeType = imageUrl.match(/^data:([^;]+);/)?.[1];
const compressedUrl = canvas.toDataURL(mimeType);
resolve(compressedUrl); resolve(compressedUrl);
}; };
img.onerror = (error) => reject(error); img.onerror = (error) => reject(error);