Commit 26885eb1 by linjinhong

fix:修改问题

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