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
+55.3k Golang : Unmarshal JSON from http response
+11.5k Golang : Generate DSA private, public key and PEM files example
+17.9k Golang : How to make a file read only and set it to writable again?
+6.9k Golang : How to setup a disk space used monitoring service with Telegram bot
+22.7k Golang : Strings to lowercase and uppercase example
+9.5k Golang : Changing a RGBA image number of channels with OpenCV
+10.1k Golang : Edge detection with Sobel method
+7.5k Golang : Get YouTube playlist
+17.7k Golang : Read data from config file and assign to variables
+4.6k JavaScript : Rounding number to decimal formats to display currency
+7.1k Restart Apache or Nginx web server without password prompt
+12.2k Golang : calculate elapsed run time