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
+10.2k Golang : Check a web page existence with HEAD request example
+19.9k Golang : How to get time from unix nano example
+9.3k Golang : Generate random Chinese, Japanese, Korean and other runes
+21.2k Golang : Convert(cast) string to rune and back to string example
+6.3k Javascript : Generate random key with specific length
+6.9k Golang : Decode XML data from RSS feed
+22.2k Golang : Convert seconds to minutes and remainder seconds
+11.5k Golang : Handle API query by curl with Gorilla Queries example
+9.6k Golang : How to generate Code 39 barcode?
+7.2k CloudFlare : Another way to get visitor's real IP address
+18.5k Golang : Example for RSA package functions
+10.6k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery