From ff5c511eca98b2eb0d22559524062a0f88486aae Mon Sep 17 00:00:00 2001 From: 24kycj <1637269896@qq.com> Date: Sat, 15 Nov 2025 15:42:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- design1.html | 8 ++++++++ design2.html | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/design1.html b/design1.html index 8635afd..0fb5b87 100644 --- a/design1.html +++ b/design1.html @@ -677,11 +677,19 @@ } } } + // 如果没有找到任何非透明像素,直接返回,不进行裁剪 + if (pix.x.length === 0 || pix.y.length === 0) { + return; + } pix.x.sort(fn); pix.y.sort(fn); n = pix.x.length - 1; w = pix.x[n] - pix.x[0]; h = pix.y[n] - pix.y[0]; + // 确保宽度和高度是有效的正数 + if (w <= 0 || h <= 0 || isNaN(w) || isNaN(h)) { + return; + } var cut = ctx.getImageData(pix.x[0], pix.y[0], w, h); canvas.width = w; canvas.height = h; diff --git a/design2.html b/design2.html index 82e266a..1014524 100644 --- a/design2.html +++ b/design2.html @@ -649,11 +649,19 @@ } } } + // 如果没有找到任何非透明像素,直接返回,不进行裁剪 + if (pix.x.length === 0 || pix.y.length === 0) { + return; + } pix.x.sort(fn); pix.y.sort(fn); n = pix.x.length - 1; w = pix.x[n] - pix.x[0]; h = pix.y[n] - pix.y[0]; + // 确保宽度和高度是有效的正数 + if (w <= 0 || h <= 0 || isNaN(w) || isNaN(h)) { + return; + } var cut = ctx.getImageData(pix.x[0], pix.y[0], w, h); canvas.width = w; canvas.height = h;