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 :

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

Advertisement