Golang image.jpeg.Decode function example

package image/jpeg

Golang image.jpeg.Decode 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()

 img, err := jpeg.Decode(imgfile) // <----- here

 if err != nil {
 fmt.Println(err)
 os.Exit(1)
 }

 bounds := img.Bounds()
 cmodel := img.ColorModel()
 at := img.At(100, 100)

 fmt.Println(bounds)
 fmt.Println(cmodel)
 fmt.Println(at)
 }

Sample output :

(0,0)-(1020,589)

&{0x89a00}

{84 161 78}

Reference :

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

Advertisement