From 5374cb9ecb32e9823bb35747402fe66f4ed5ae80 Mon Sep 17 00:00:00 2001 From: AI Bot Date: Thu, 30 Jul 2026 18:09:18 +0530 Subject: [PATCH] Compress imported model textures via WebP 0.8 to prevent 413 Payload Too Large on project save --- src/pages/Editor.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pages/Editor.tsx b/src/pages/Editor.tsx index d412b55..4b9d344 100644 --- a/src/pages/Editor.tsx +++ b/src/pages/Editor.tsx @@ -1380,13 +1380,21 @@ export default function Editor() { // Fallback: draw ImageBitmap or HTMLImageElement to canvas to extract data URL try { + const MAX = 1024; + let scale = 1; + if (img.width > MAX || img.height > MAX) { + scale = MAX / Math.max(img.width, img.height); + } + const cw = Math.round((img.width || 1024) * scale); + const ch = Math.round((img.height || 1024) * scale); + const canvas = document.createElement('canvas'); - canvas.width = img.width || 1024; - canvas.height = img.height || 1024; + canvas.width = cw; + canvas.height = ch; const ctx = canvas.getContext('2d'); if (ctx) { - ctx.drawImage(img, 0, 0); - return canvas.toDataURL('image/png'); + ctx.drawImage(img, 0, 0, cw, ch); + return canvas.toDataURL('image/webp', 0.8); } } catch (e) { console.error('Error extracting texture URL:', e);