func procImage(fileName string) (string, error) { reader, err := os.Open(fileName) if err != nil { fmt.Errorf("Failed to open image with error: %s\n", err) return "", err } defer reader.Close() src, _, err := image.Decode(reader) if err != nil { fmt.Errorf("Failed to decode image with error: %s\n", err) return "", err } g := gift.New( gift.Invert(), ) dst := image.NewRGBA(g.Bounds(src.Bounds())) g.Draw(dst, src) var opt jpeg.Options opt.Quality = 100 fileName = fileName + "_processed.jpg" out, _ := os.Create(fileName) err = jpeg.Encode(out, dst, &opt) if err != nil { fmt.Errorf("Failed to encode image with error: %s\n", err) return "", err } return fileName, nil }
// take an image and revert its rgb channels (255-channel) func invert(img image.Image) image.Image { g := gift.New(gift.Grayscale(), gift.Invert()) dst := image.NewRGBA(g.Bounds(img.Bounds())) g.Draw(dst, img) return dst }