diff --git a/README.md b/README.md index f6f8191..4f4c744 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,7 @@ # imageoptimizer imageoptimizer is a tool for bulk compression og JPG images. It will re-compress original images and replace them if the savings is -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. +more than the requested percentage difference and optionally if the original file is bigger than a cefrtain size. By default it operates 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? diff --git a/main.go b/main.go index 91e4e4b..908ba5d 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,8 @@ type config struct { Replace bool StartingPath string Quiet bool + AtLeast uint + } type stats struct { @@ -33,6 +35,7 @@ func main() { flag.UintVar(&c.Diff, "diff", 25, "Percent difference required to replace original image.") 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.UintVar(&c.AtLeast, "atleast", 0, "Ignore images that aren't at least this many kilobytes") 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)") flag.Parse() @@ -102,6 +105,13 @@ func doSingleImage(f string, c config, s stats) stats { fmt.Printf("Error reading file %s: %s\n", f, err.Error()) return s } + if st.Size() < int64(c.AtLeast) { + s.StartingBytes += uint64(st.Size()) + if !c.Quiet { + fmt.Printf("Ignoring %s as %d bytes are below threashold", f, st.Size()) + } + return s + } in, err := os.Open(f) if err != nil { fmt.Printf("Error opening file %s: %s\n", f, err.Error())