Rename CompressLevel to Quality for clarity

This commit is contained in:
Your Name 2022-02-01 10:41:50 -05:00
parent 03fa819716
commit 417a253ac7
2 changed files with 13 additions and 7 deletions

View File

@ -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
```

View File

@ -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