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.6k CodeIgniter : Import Linkedin data
+7.6k Golang : How to handle file size larger than available memory panic issue
+29.5k Golang : Save map/struct to JSON or XML file
+7.5k Android Studio : How to detect camera, activate and capture example
+7.2k Golang : Transform lisp or spinal case to Pascal case example
+5.5k Golang : Stop goroutine without channel
+4.7k Linux : sudo yum updates not working
+12.4k Golang : Validate email address
+21.9k Golang : How to reverse slice or array elements order
+9.5k Golang : Detect Pascal, Kebab, Screaming Snake and Camel cases
+15.7k Golang : Force download file example
+18k Golang : Simple client server example