|
|
@@ -19,9 +19,11 @@ async function main() {
|
|
|
const h = image.getHeight()
|
|
|
console.log('TIFF size:', w, 'x', h)
|
|
|
|
|
|
- // Target size matching current preview
|
|
|
- const targetW = 6181
|
|
|
- const targetH = 8192
|
|
|
+ // 控制生成纹理尺寸:原图 14997x19876 太大,浏览器加载 123MB PNG 容易失败。
|
|
|
+ // 4096 宽按原比例缩放后约 5425 高,文件体积降到 1/4 左右,仍然足够清晰。
|
|
|
+ const targetW = 4096
|
|
|
+ const targetH = Math.round(targetW * h / w)
|
|
|
+ console.log('Target size:', targetW, 'x', targetH)
|
|
|
|
|
|
console.log('Reading rasters at target size...')
|
|
|
const data = await image.readRasters({ width: targetW, height: targetH, samples: [0, 1, 2] })
|
|
|
@@ -44,7 +46,7 @@ async function main() {
|
|
|
console.log('Black pixels masked:', blackCount)
|
|
|
|
|
|
await sharp(rgba, { raw: { width: targetW, height: targetH, channels: 4 } })
|
|
|
- .png({ compressionLevel: 6 })
|
|
|
+ .png({ compressionLevel: 9, adaptiveFiltering: true })
|
|
|
.toFile(outPath)
|
|
|
|
|
|
console.log('Saved:', outPath)
|