Created
February 25, 2016 17:54
-
-
Save dryaf/825a1197e404538d2dda to your computer and use it in GitHub Desktop.
golang invert png images in current folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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