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
+11.6k Golang : Surveillance with web camera and OpenCV
+18.4k Golang : Logging with logrus
+9.4k Golang : Apply Histogram Equalization to color images
+10k Golang : Channels and buffered channels examples
+5.8k Golang : Fix opencv.LoadHaarClassifierCascade The node does not represent a user object error
+6.8k Golang : Calculate pivot points for a cross
+30.4k Golang : How to verify uploaded file is image or allowed file types
+11.5k Golang : Change date format to yyyy-mm-dd
+24.5k Golang : Change file read or write permission example
+7.8k Golang : Load DSA public key from file example
+18.5k Golang : Example for RSA package functions
+6.4k Golang : Handling image beyond OpenCV video capture boundary