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 :

http://golang.org/pkg/image/png/#DecodeConfig

Advertisement