@zhaoshijun/compress 1.3.0 → 1.4.0

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/bin/compress.js CHANGED
@@ -29,6 +29,8 @@ program
29
29
  .option('--dry-run', '仅列出将处理的文件,不写入磁盘')
30
30
  .option('-q, --quiet', '静默模式,仅输出错误')
31
31
  .option('-w, --watermark', '启用水印')
32
+ .option('--keep-metadata', '保留图片元数据(拍摄时间、地点等)')
33
+ .option('-o, --output <dir>', '输出目录')
32
34
  .action(async (options) => {
33
35
  try {
34
36
  const startTime = Date.now();
@@ -38,6 +40,8 @@ program
38
40
 
39
41
  // 合并命令行选项
40
42
  if (options.backup !== undefined) config.backup = options.backup;
43
+ if (options.keepMetadata !== undefined) config.keepMetadata = options.keepMetadata;
44
+ if (options.output !== undefined) config.output = options.output;
41
45
 
42
46
  // 确定输入源
43
47
  // 如果 config.input 未定义,则默认为当前目录 '**/*.{jpg,jpeg,png,webp}'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhaoshijun/compress",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Image compression CLI and Vite plugin",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,6 +1,7 @@
1
1
  export const defaultConfig = {
2
2
  output: './compressed',
3
3
  quality: 88,
4
+ keepMetadata: false,
4
5
  jpegOptions: {
5
6
  quality: 88,
6
7
  progressive: false,
@@ -127,5 +127,10 @@ export async function compressImage(input, options, filePath) {
127
127
  }
128
128
  }
129
129
 
130
+ // 如果需要保留元数据
131
+ if (options.keepMetadata) {
132
+ instance = instance.withMetadata();
133
+ }
134
+
130
135
  return instance.toBuffer();
131
136
  }