Skip to content

Instantly share code, notes, and snippets.

@dryaf
Created February 25, 2016 17:54
Show Gist options
  • Save dryaf/825a1197e404538d2dda to your computer and use it in GitHub Desktop.
Save dryaf/825a1197e404538d2dda to your computer and use it in GitHub Desktop.
golang invert png images in current folder
package main
import (
"io/ioutil"
"log"
"github.com/disintegration/imaging"
"image"
"os"
)
func main() {
files, err := ioutil.ReadDir(".")
if err != nil {
log.Fatal(err)
}
for _, file := range files {
if len(file.Name()) > 4 && file.Name()[len(file.Name())-4:] == ".png" {
fio, err := os.Open(file.Name())
if err!= nil {
log.Println(err)
return
}
ip, str, err := image.Decode(fio)
if err!= nil {
log.Println(str, err)
}
inverted := imaging.Invert(ip)
imaging.Save(inverted,"./inverted/"+file.Name())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment