Golang image.gif.DecodeConfig function example

package image/gif

Golang image.gif.DecodeConfig function usage example

 package main

 import (
 "fmt"
 "image/gif"
 "os"
 )

 func main() {
 imgfile, err := os.Open("./img.gif")

 if err != nil {
 fmt.Println("img.gif file not found!")
 os.Exit(1)
 }

 defer imgfile.Close()

 imgCfg, err := gif.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)
 }

Reference :

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

Advertisement