mediac 1.6.8 → 1.7.1
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/cmd/cmd_compress.js +19 -8
- package/cmd/cmd_ffmpeg.js +817 -0
- package/cmd/cmd_remove.js +83 -62
- package/cmd/cmd_rename.js +3 -6
- package/cmd/cmd_shared.js +2 -2
- package/lib/core.js +95 -2
- package/lib/ffprobe.js +106 -0
- package/lib/file.js +33 -3
- package/lib/helper.js +71 -15
- package/package.json +14 -5
- package/scripts/media_cli.js +3 -5
- package/.vscode/settings.json +0 -3
- package/cmd/cmd_audiotag.js +0 -3
- package/labs/cjk_demo.js +0 -54
- package/labs/download_urls.js +0 -82
- package/labs/file_cli.js +0 -153
- package/labs/file_organize.js +0 -99
- package/labs/fs_demo.js +0 -17
- package/labs/gdh_gpt35.js +0 -95
- package/labs/gdh_gpt4.js +0 -94
- package/labs/git_date_header_001.js +0 -127
- package/labs/git_date_header_002.js +0 -88
- package/labs/make_thumbs.js +0 -157
- package/labs/merge_dir.js +0 -106
- package/labs/merge_dir_cli.js +0 -107
- package/labs/path_test.js +0 -14
- package/labs/pic_exif_rename.js +0 -131
- package/labs/print_unicode.js +0 -79
- package/labs/strftime.js +0 -84
- package/labs/string_format.js +0 -76
- package/labs/test.js +0 -55
- package/labs/unicode_test.js +0 -101
- package/labs/yargs_demo.js +0 -34
- package/labs/zip_test.js +0 -82
package/cmd/cmd_compress.js
CHANGED
|
@@ -267,11 +267,13 @@ async function preCompress(f, options = {}) {
|
|
|
267
267
|
const st = await fs.stat(fileSrc)
|
|
268
268
|
const m = await sharp(fileSrc).metadata()
|
|
269
269
|
try {
|
|
270
|
+
// 跳过以前由mediac压缩过的图片,避免重复压缩
|
|
271
|
+
// 可能需要添加一个命令行参数控制
|
|
270
272
|
if (m?.exif) {
|
|
271
273
|
const md = exif(m.exif)?.Image
|
|
272
|
-
if (md
|
|
274
|
+
if (md.Copyright?.includes("mediac")
|
|
273
275
|
|| md.Software?.includes("mediac")
|
|
274
|
-
|| md.Artist?.includes("mediac"))
|
|
276
|
+
|| md.Artist?.includes("mediac")) {
|
|
275
277
|
log.info(logTag, "skip:", fileDst)
|
|
276
278
|
return {
|
|
277
279
|
...f,
|
|
@@ -289,12 +291,7 @@ async function preCompress(f, options = {}) {
|
|
|
289
291
|
log.fileLog(`ExifErr: <${fileSrc}> ${error.message}`, logTag)
|
|
290
292
|
}
|
|
291
293
|
|
|
292
|
-
const
|
|
293
|
-
m.width > m.height ? maxWidth : Math.round((maxWidth * m.width) / m.height)
|
|
294
|
-
const newHeight = Math.round((newWidth * m.height) / m.width)
|
|
295
|
-
|
|
296
|
-
const dstWidth = newWidth > m.width ? m.width : newWidth
|
|
297
|
-
const dstHeight = newHeight > m.height ? m.height : newHeight
|
|
294
|
+
const { dstWidth, dstHeight } = calculateImageScale(m.width, m.height, maxWidth)
|
|
298
295
|
if (f.total < 1000 || f.index > f.total - 1000) {
|
|
299
296
|
log.show(logTag, `${f.index}/${f.total}`,
|
|
300
297
|
helper.pathShort(fileSrc),
|
|
@@ -358,4 +355,18 @@ async function purgeSrcFiles(results) {
|
|
|
358
355
|
const deleted = await pMap(toDelete, deletecFunc, { concurrency: cpus().length * 8 })
|
|
359
356
|
log.showCyan(logTag, `${deleted.filter(Boolean).length} files are safely removed`)
|
|
360
357
|
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// 给定图片长宽,给定长边数值,计算缩放后的长宽,只缩小不放大
|
|
361
|
+
function calculateImageScale(imgWidth, imgHeight, maxSide) {
|
|
362
|
+
// 不需要缩放的情况
|
|
363
|
+
if (iw <= maxSide && ih <= maxSide) {
|
|
364
|
+
return { dstWidth: iw, dstHeight: ih }
|
|
365
|
+
}
|
|
366
|
+
// 计算缩放比例
|
|
367
|
+
let scaleFactor = maxSide / Math.max(imgWidth, imgHeight)
|
|
368
|
+
// 计算新的长宽
|
|
369
|
+
let dstWidth = Math.round(imgWidth * scaleFactor)
|
|
370
|
+
let dstHeight = Math.round(imgHeight * scaleFactor)
|
|
371
|
+
return { dstWidth, dstHeight }
|
|
361
372
|
}
|