Add flag to ignore file suffixes

This commit is contained in:
Your Name 2022-02-02 15:47:16 -05:00
parent c538a9acc0
commit 05e534fde5
1 changed files with 5 additions and 3 deletions

View File

@ -22,6 +22,7 @@ type config struct {
AtLeast uint AtLeast uint
MaxWidth uint MaxWidth uint
MaxHeight uint MaxHeight uint
IgnoreSuffix bool
} }
@ -40,6 +41,7 @@ func main() {
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.UintVar(&c.AtLeast, "atleast", 0, "Ignore images that aren't at least this many kilobytes")
flag.BoolVar(&c.IgnoreSuffix, "ignoresuffix", false, "Ignore suffix on filenames and attempt to treat everything as a JPG")
flag.UintVar(&c.MaxWidth, "maxwidth", 0, "Maximum width, scale images bigger to fit within this width. 0 ignores. Won't replace unless it meets the diff threashold.") flag.UintVar(&c.MaxWidth, "maxwidth", 0, "Maximum width, scale images bigger to fit within this width. 0 ignores. Won't replace unless it meets the diff threashold.")
flag.UintVar(&c.MaxHeight, "maxheight", 0, "Maximum height, scale images bigger to fit within this height. 0 ignores. Won't replace until it meets the diff threashold.") flag.UintVar(&c.MaxHeight, "maxheight", 0, "Maximum height, scale images bigger to fit within this height. 0 ignores. Won't replace until it meets the diff threashold.")
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")
@ -74,8 +76,8 @@ func main() {
} }
for _, f := range d { for _, f := range d {
if !f.IsDir() { if !f.IsDir() {
suf := strings.ToLower(filepath.Ext(f.Name())) ext := strings.ToLower(filepath.Ext(f.Name()))
if suf == ".jpg" || suf == ".jpeg" { if c.IgnoreSuffix || ext == ".jpg" || ext == ".jpeg" {
filelist = append(filelist, f.Name()) filelist = append(filelist, f.Name())
} }
@ -84,7 +86,7 @@ func main() {
} else { } else {
filepath.WalkDir(c.StartingPath, func(path string, d fs.DirEntry, err error) error { filepath.WalkDir(c.StartingPath, func(path string, d fs.DirEntry, err error) error {
ext := strings.ToLower(filepath.Ext(path)) ext := strings.ToLower(filepath.Ext(path))
if ext == ".jpg" || ext == ".jpeg" { if c.IgnoreSuffix || ext == ".jpg" || ext == ".jpeg" {
filelist = append(filelist, path) filelist = append(filelist, path)
} }
return nil return nil