Golang image.png.DecodeConfig function example
package image/png
Golang image.png.DecodeConfig function usage example
package main
import (
"fmt"
"image/png"
"os"
)
func main() {
imgfile, err := os.Open("./img.png")
if err != nil {
fmt.Println("img.png file not found!")
os.Exit(1)
}
defer imgfile.Close()
imgCfg, err := png.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 :
&{0x90ab0}
600
849
Reference :
Advertisement
Something interesting
Tutorials
+13.9k Golang : How to determine if a year is leap year?
+6k Linux/MacOSX : Search for files by filename and extension with find command
+5.3k Golang : How to deal with configuration data?
+13.4k Golang : Verify token from Google Authenticator App
+8.4k Golang : Ackermann function example
+10.4k Golang : cannot assign type int to value (type uint8) in range error
+9.4k Golang : Find the length of big.Int variable example
+5.8k Javascript : How to replace HTML inside <div>?
+7k Web : How to see your website from different countries?
+13.7k Golang : Tutorial on loading GOB and PEM files
+25.2k Golang : Storing cookies in http.CookieJar example
+7.2k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream