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 : Temperatures conversion example
+25.4k Golang : How to write CSV data to file
+19.7k Golang : Compare floating-point numbers
+39.6k Golang : Convert to io.ReadSeeker type
+26k Golang : Convert(cast) string to uint8 type and back to string
+5.2k Golang : Intercept, inject and replay HTTP traffics from web server
+17.8k Golang : Convert IPv4 address to decimal number(base 10) or integer
+8.7k Golang : Populate or initialize struct with values example
+9.7k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral
+12.1k Golang : Search and extract certain XML data example
+17.1k Golang : Multi threading or run two processes or more example
+8.9k Golang : Generate Codabar