From 417a253ac7bf54068df6a4e7d864b8934f88a642 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 1 Feb 2022 10:41:50 -0500 Subject: [PATCH] Rename CompressLevel to Quality for clarity --- README.md | 12 +++++++++--- main.go | 8 ++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 419ef43..f6f8191 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,22 @@ imageoptimizer is a tool for bulk compression og JPG images. It will re-compress more than the requested percentage difference, default is 25%. By defaul it operated in a "dry run" mode where images are not replaced but individual and total savings are reported at the end, unless you supply the '-replace' flag. +# why? + +Poorly optimized images in most contexts waste space and bandwidth unnecessarily. JPEG compression was designed to highly optimize photos with +little or no visually identifiable differences in default conditions, and for scenarios where absolute quality is less important it can compress +even farther. Generally quality levels below 75 are where you start to notice a difference. + # usage Recursively check all images starting from the current path. Calculate actions and total svings but don't make any changes. ``` -imageoptimizer -recursive -compresslevel 85 -diff 25 +imageoptimizer -recursive -diff 25 ``` -Replace images in the current path with a compressed version if compressing at 80% reduces file size by at least 30% +Replace images in the current path with a compressed version if compressing at 80% quality reduces file size by at least 30% ``` -imageoptimizer -compresslevel --replace --diff 30 +imageoptimizer -quality 80 --replace --diff 30 ``` diff --git a/main.go b/main.go index 03a35d3..dcda30f 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( type config struct { Recursive bool Diff uint - CompressLevel uint + Quality uint Replace bool StartingPath string Quiet bool @@ -31,7 +31,7 @@ func main() { var c config flag.BoolVar(&c.Recursive, "recursive", false, "Process folders recursively (default false).") flag.UintVar(&c.Diff, "diff", 25, "Percent difference required to replace original image.") - flag.UintVar(&c.CompressLevel, "compresslevel", 85, "JPG compression level.") + flag.UintVar(&c.Quality, "quality", 85, "JPG compression quality level.") flag.BoolVar(&c.Quiet, "quiet", false, "Less output - don't print per-file detail") flag.StringVar(&c.StartingPath, "startingpath", ".", "Start from this path instead of current working dir") flag.BoolVar(&c.Replace, "replace", false, "Replace with compressed versions if criteria are met. Otheriwse, just test and report, don't replace any images. (default false)") @@ -42,7 +42,7 @@ func main() { fmt.Println("Fatal: diff out of range (-99)") fail = true } - if c.CompressLevel > 99 { + if c.Quality > 99 { fmt.Println("Fatal: compresslevel out of range (1-99)") fail = true } @@ -118,7 +118,7 @@ func doSingleImage(f string, c config, s stats) stats { fmt.Printf("Couldn't open out temprary file: %s\n", err.Error()) return s } - err = jpeg.Encode(out, orig, &jpeg.Options{Quality: int(c.CompressLevel)}) + err = jpeg.Encode(out, orig, &jpeg.Options{Quality: int(c.Quality)}) if err != nil { fmt.Printf("Error re-encoding image %s: %s\n", f, err.Error()) return s