Upload imageProcessor.js
Browse files
src/lib/imageProcessor.js
CHANGED
|
@@ -18,6 +18,7 @@ class ImageProcessor {
|
|
| 18 |
this.OPTIMAL_SEGMENT_HEIGHT = 2500 // 理想片段高度
|
| 19 |
this.MAX_SEGMENT_HEIGHT = 3000 // 最大片段高度
|
| 20 |
this.MIN_SEGMENT_HEIGHT = 2000 // 最小片段高度
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
/**
|
|
@@ -70,7 +71,13 @@ class ImageProcessor {
|
|
| 70 |
}
|
| 71 |
|
| 72 |
// 计算理想的片段数量(基于理想高度)
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
// 计算每个片段的理想高度(不考虑重叠)
|
| 76 |
const baseSegmentHeight = Math.floor(height / idealSegmentCount)
|
|
|
|
| 18 |
this.OPTIMAL_SEGMENT_HEIGHT = 2500 // 理想片段高度
|
| 19 |
this.MAX_SEGMENT_HEIGHT = 3000 // 最大片段高度
|
| 20 |
this.MIN_SEGMENT_HEIGHT = 2000 // 最小片段高度
|
| 21 |
+
this.MAX_SEGMENTS = 4 // 最大片段数量限制,避免API处理问题
|
| 22 |
}
|
| 23 |
|
| 24 |
/**
|
|
|
|
| 71 |
}
|
| 72 |
|
| 73 |
// 计算理想的片段数量(基于理想高度)
|
| 74 |
+
let idealSegmentCount = Math.ceil(height / this.OPTIMAL_SEGMENT_HEIGHT)
|
| 75 |
+
|
| 76 |
+
// 如果片段数量超过最大限制,强制减少片段数量
|
| 77 |
+
if (idealSegmentCount > this.MAX_SEGMENTS) {
|
| 78 |
+
idealSegmentCount = this.MAX_SEGMENTS
|
| 79 |
+
console.log(`[智能切割] 片段数量超限,强制限制为${this.MAX_SEGMENTS}个片段`)
|
| 80 |
+
}
|
| 81 |
|
| 82 |
// 计算每个片段的理想高度(不考虑重叠)
|
| 83 |
const baseSegmentHeight = Math.floor(height / idealSegmentCount)
|