add minimum size to process option
This commit is contained in:
parent
5e8d11d327
commit
91ca030474
|
@ -1,8 +1,7 @@
|
||||||
# imageoptimizer
|
# imageoptimizer
|
||||||
|
|
||||||
imageoptimizer is a tool for bulk compression og JPG images. It will re-compress original images and replace them if the savings is
|
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
|
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.
|
||||||
but individual and total savings are reported at the end, unless you supply the '-replace' flag.
|
|
||||||
|
|
||||||
# why?
|
# why?
|
||||||
|
|
||||||
|
|
10
main.go
10
main.go
|
@ -17,6 +17,8 @@ type config struct {
|
||||||
Replace bool
|
Replace bool
|
||||||
StartingPath string
|
StartingPath string
|
||||||
Quiet bool
|
Quiet bool
|
||||||
|
AtLeast uint
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type stats struct {
|
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.Diff, "diff", 25, "Percent difference required to replace original image.")
|
||||||
flag.UintVar(&c.Quality, "quality", 85, "JPG compression quality 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.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.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.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()
|
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())
|
fmt.Printf("Error reading file %s: %s\n", f, err.Error())
|
||||||
return s
|
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)
|
in, err := os.Open(f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error opening file %s: %s\n", f, err.Error())
|
fmt.Printf("Error opening file %s: %s\n", f, err.Error())
|
||||||
|
|
Loading…
Reference in New Issue