Add flag to ignore file suffixes
This commit is contained in:
parent
c538a9acc0
commit
05e534fde5
8
main.go
8
main.go
|
@ -22,6 +22,7 @@ type config struct {
|
|||
AtLeast uint
|
||||
MaxWidth uint
|
||||
MaxHeight uint
|
||||
IgnoreSuffix bool
|
||||
|
||||
}
|
||||
|
||||
|
@ -40,6 +41,7 @@ func main() {
|
|||
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.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.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")
|
||||
|
@ -74,8 +76,8 @@ func main() {
|
|||
}
|
||||
for _, f := range d {
|
||||
if !f.IsDir() {
|
||||
suf := strings.ToLower(filepath.Ext(f.Name()))
|
||||
if suf == ".jpg" || suf == ".jpeg" {
|
||||
ext := strings.ToLower(filepath.Ext(f.Name()))
|
||||
if c.IgnoreSuffix || ext == ".jpg" || ext == ".jpeg" {
|
||||
filelist = append(filelist, f.Name())
|
||||
}
|
||||
|
||||
|
@ -84,7 +86,7 @@ func main() {
|
|||
} else {
|
||||
filepath.WalkDir(c.StartingPath, func(path string, d fs.DirEntry, err error) error {
|
||||
ext := strings.ToLower(filepath.Ext(path))
|
||||
if ext == ".jpg" || ext == ".jpeg" {
|
||||
if c.IgnoreSuffix || ext == ".jpg" || ext == ".jpeg" {
|
||||
filelist = append(filelist, path)
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue