Golang image.jpeg.DecodeConfig function example
package image/jpeg
Golang image.jpeg.DecodeConfig function usage example
package main
import (
"fmt"
"image/jpeg"
"os"
)
func main() {
imgfile, err := os.Open("./img.jpg")
if err != nil {
fmt.Println("img.jpg file not found!")
os.Exit(1)
}
defer imgfile.Close()
imgCfg, err := jpeg.DecodeConfig(imgfile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
cmodel := imgCfg.ColorModel
width := imgCfg.Width
height := imgCfg.Height
fmt.Println(cmodel)
fmt.Println(width)
fmt.Println(height)
}
Sample output :
&{0x89940}
1020
589
Reference :
Advertisement
Something interesting
Tutorials
+9.2k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+15k Golang : package is not in GOROOT during compilation
+7.8k Golang : Load DSA public key from file example
+11.3k Golang : How to pipe input data to executing child process?
+19.1k Mac OSX : Homebrew and Golang
+7.5k Golang : Detect sample rate, channels or latency with PortAudio
+14k Golang : convert rune to unicode hexadecimal value and back to rune character
+6.3k Golang : Extract sub-strings
+10.5k Golang : Create matrix with Gonum Matrix package example
+9.4k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+10.8k Android Studio : Checkbox for user to select options example