Skip to content

Instantly share code, notes, and snippets.

@rolandvarga
Last active July 4, 2020 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolandvarga/94f7a1ed2fd96fbf91a6e314958e3646 to your computer and use it in GitHub Desktop.
Save rolandvarga/94f7a1ed2fd96fbf91a6e314958e3646 to your computer and use it in GitHub Desktop.
func parseExt(path string) string {
split := strings.Split(path, ".")
return "." + split[len(split)-1]
}
func today() string {
now := time.Now()
return now.Format("20060102")
}
func main() {
...
newExt := parseExt(f.Name)
newFile := *dest + "/" + f.Name[0:len(f.Name)-len(newExt)] + "_GRAYSCALED_" + today() + newExt
out, err := os.Create(newFile)
if err != nil {
fmt.Printf("error creating destination image path '%s': %s\n", newFile, err.Error())
continue
}
defer out.Close()
err = jpeg.Encode(out, gray, nil)
if err != nil {
fmt.Printf("error saving image at destination '%s': %s\n", newFile, err.Error())
continue
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment