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
+9k Golang : Query string with space symbol %20 in between
+5.3k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+3.8k Golang : Compound interest over time example
+1.7k Java : Get FX sentiment from website example
+4.1k PHP : How to check if an array is empty ?
+17.8k Golang : Round float to precision example
+5.9k Golang : Get all countries currencies code in JSON format
+13.6k Golang : Logging with logrus
+9.3k Elastic Search : Mapping date format and sort by date
+26.1k Golang : Call a function after some delay(time.Sleep and Tick)
+4.4k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+3.4k Golang : Get S3 or CloudFront object or file information