Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
electron-printer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhuzhequan
electron-printer
Commits
26885eb1
Commit
26885eb1
authored
Mar 27, 2026
by
linjinhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:修改问题
parent
28c8688b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
7 deletions
+23
-7
src/server/utils/setImage.js
+23
-7
No files found.
src/server/utils/setImage.js
View file @
26885eb1
...
...
@@ -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
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment