@zhaoshijun/compress 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhaoshijun/compress",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "Image compression CLI and Vite plugin",
5
5
  "type": "module",
6
6
  "bin": {
@@ -31,7 +31,9 @@ export async function compressImage(input, options, filePath) {
31
31
  }
32
32
  }
33
33
 
34
- // 重新获取 resize 后的尺寸(用于水印)
34
+ // 确保resize操作完成后再获取metadata
35
+ const resizedBuffer = await instance.toBuffer();
36
+ instance = sharp(resizedBuffer);
35
37
  const resizedMetadata = await instance.metadata();
36
38
  const format = resizedMetadata.format;
37
39
 
@@ -101,10 +101,15 @@ async function createTiledWatermark(width, height, text, options) {
101
101
  }
102
102
  })
103
103
  .composite(composites)
104
- .extract({ left: 0, top: 0, width, height })
104
+ .extract({ left: 0, top: 0, width: Math.min(tiledWidth, width), height: Math.min(tiledHeight, height) })
105
105
  .png()
106
106
  .toBuffer();
107
107
 
108
+ const finalMeta = await sharp(tiledWatermark).metadata();
109
+ if (finalMeta.width !== width || finalMeta.height !== height) {
110
+ console.error(`Watermark size mismatch: expected ${width}x${height}, got ${finalMeta.width}x${finalMeta.height}`);
111
+ }
112
+
108
113
  return tiledWatermark;
109
114
  }
110
115