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
+5.5k PHP : Get client IP address
+5.1k Golang : Intercept, inject and replay HTTP traffics from web server
+7.7k Golang : Get final or effective URL with Request.URL example
+6.7k Restart Apache or Nginx web server without password prompt
+9.4k Golang : List available AWS regions
+18.6k Golang : Populate dropdown with html/template example
+7.2k Golang : Shuffle strings array
+27.5k Golang : Move file to another directory
+18.8k Golang : Execute shell command
+9.4k Golang : Resumable upload to Google Drive(RESTful) example
+15k Golang : Force download file example
+6.4k Golang : Muxing with Martini example