From 4aea178ab01a14d6b0017c7f64ffbe05b370960f Mon Sep 17 00:00:00 2001 From: wood chen Date: Tue, 22 Oct 2024 18:20:59 +0800 Subject: [PATCH] =?UTF-8?q?100KB=E4=BB=A5=E4=B8=8B=E4=B8=8D=E5=A4=84?= =?UTF-8?q?=E7=90=86,=20=E8=B0=83=E6=95=B4=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- encoder/encoder.go | 10 ++++++++-- handler/router.go | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/encoder/encoder.go b/encoder/encoder.go index c1180e5..5d2afe1 100644 --- a/encoder/encoder.go +++ b/encoder/encoder.go @@ -289,6 +289,12 @@ func convertLog(itype, rawPath string, optimizedPath string, quality int) { log.Error(err) return } - log.Infof("%s@%d%%: %s->%s %d->%d %.2f%% deflated", itype, quality, - rawPath, optimizedPath, oldf.Size(), newf.Size(), float32(newf.Size())/float32(oldf.Size())*100) + + // 计算压缩率 + deflateRate := float32(newf.Size()) / float32(oldf.Size()) * 100 + + // 记录转换信息 + log.Infof("图像转换: 类型=%s, 质量=%d%%", itype, quality) + log.Infof("文件路径: 原始=%s, 优化=%s", rawPath, optimizedPath) + log.Infof("文件大小: 原始=%d字节, 优化=%d字节, 压缩率=%.2f%%", oldf.Size(), newf.Size(), deflateRate) } diff --git a/handler/router.go b/handler/router.go index 3713819..1c9dd65 100644 --- a/handler/router.go +++ b/handler/router.go @@ -238,7 +238,7 @@ func Convert(c *fiber.Ctx) error { } if isSmall { - log.Infof("文件 %s 小于200KB,跳过转换", rawImageAbs) + log.Infof("文件 %s 小于100KB,跳过转换", rawImageAbs) return c.SendFile(rawImageAbs) }