Commit 26885eb1 by linjinhong

fix:修改问题

parent 28c8688b
...@@ -483,6 +483,7 @@ async function checkImageOutsideGrid() { ...@@ -483,6 +483,7 @@ async function checkImageOutsideGrid() {
}; };
// ===================== 【判断1】图片是否大于台版 ===================== // ===================== 【判断1】图片是否大于台版 =====================
const isImageBiggerThanGrid = const isImageBiggerThanGrid =
imgDisplayInfo.width > grid.width || imgDisplayInfo.height > grid.height; imgDisplayInfo.width > grid.width || imgDisplayInfo.height > grid.height;
...@@ -523,12 +524,16 @@ async function checkImageOutsideGrid() { ...@@ -523,12 +524,16 @@ async function checkImageOutsideGrid() {
const alphaThreshold = 1; const alphaThreshold = 1;
const imgNaturalWidth = imgMetadata.width; const imgNaturalWidth = imgMetadata.width;
const imgNaturalHeight = imgMetadata.height; const imgNaturalHeight = imgMetadata.height;
const hasAlpha = imgMetadata.channels === 4;
for (let y = 0; y < imgNaturalHeight; y++) { for (let y = 0; y < imgNaturalHeight; y++) {
if (hasOutsideValidPixel) break; if (hasOutsideValidPixel) break;
for (let x = 0; x < imgNaturalWidth; x++) { for (let x = 0; x < imgNaturalWidth; x++) {
const imgDisplayX = imgDisplayInfo.left + x * scaleX; const imgDisplayX = parseFloat(
const imgDisplayY = imgDisplayInfo.top + y * scaleY; (imgDisplayInfo.left + x * scaleX).toFixed(2),
);
const imgDisplayY = parseFloat(
(imgDisplayInfo.top + y * scaleY).toFixed(2),
);
if (isNaN(imgDisplayX) || isNaN(imgDisplayY)) continue; if (isNaN(imgDisplayX) || isNaN(imgDisplayY)) continue;
...@@ -539,11 +544,22 @@ async function checkImageOutsideGrid() { ...@@ -539,11 +544,22 @@ async function checkImageOutsideGrid() {
imgDisplayY > grid.bottom; imgDisplayY > grid.bottom;
if (isOutside) { if (isOutside) {
const pixelIndex = (y * imgNaturalWidth + x) * 4; const pixelIndex = (y * imgNaturalWidth + x) * imgMetadata.channels;
const alpha = pixels[pixelIndex + 3];
if (alpha > alphaThreshold) { // 🔥 终极兼容逻辑
let isValidPixel = false;
if (hasAlpha) {
// PNG 有透明通道:判断透明度
const alpha = pixels[pixelIndex + 3];
isValidPixel = alpha > alphaThreshold;
} else {
// JPG / 无透明通道:只要超出,一律视为有实色像素(纯白/彩色都算)
isValidPixel = true;
}
if (isValidPixel) {
hasOutsideValidPixel = true; hasOutsideValidPixel = true;
console.log(`找到超出网格的有效像素:(${x},${y})`); console.log(`✅ 检测到超出有效像素(坐标${x},${y}`);
break; break;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment