Golang : Grayscale Image
Another feature that I like about this Disintegration Imaging package is the ability to generate grayscaled image. The codes below will demonstrate how to quickly turn an image into grayscale version.
package main
import (
"fmt"
"github.com/disintegration/imaging"
"os"
"runtime"
)
func main() {
// maximize CPU usage for maximum performance
runtime.GOMAXPROCS(runtime.NumCPU())
// load original image
img, err := imaging.Open("./big.jpg")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// grayscale the image
grayimg := imaging.Grayscale(img)
// save grayscaled image
err = imaging.Save(grayimg, "./grayscaled.png")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// everything ok
fmt.Println("Done")
}
big.jpg
grayscaled.png
References :
See also : Golang : Generate thumbnails from images
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+11.7k Golang : Fuzzy string search or approximate string matching example
+12k Golang : How to parse plain email text and process email header?
+15.3k Golang : package is not in GOROOT during compilation
+9.8k Golang : Load ASN1 encoded DSA public key PEM file example
+21.3k Golang : Get password from console input without echo or masked
+6.6k Golang : Map within a map example
+5.9k Unix/Linux : How to test user agents blocked successfully ?
+6k AWS S3 : Prevent Hotlinking policy
+5.2k Golang : Check if a word is countable or not
+6.3k Linux/Unix : Commands that you need to be careful about
+6.8k Golang : When to use make or new?
+9.3k Golang : Serving HTTP and Websocket from different ports in a program example