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 :
Advertisement
Something interesting
Tutorials
+7k Golang : Levenshtein distance example
+5.4k Golang : Reclaim memory occupied by make() example
+11.1k Golang : How to determine a prime number?
+6.4k Golang : How to search a list of records or data structures
+20.3k Swift : Convert (cast) Int to int32 or Uint32
+26.1k Mac/Linux and Golang : Fix bind: address already in use error
+8.8k Golang : HTTP Routing with Goji example
+14.9k Golang : Basic authentication with .htpasswd file
+8.3k Golang : Configure Apache and NGINX to access your Go service example
+13.4k Golang : Increment string example
+5.6k PHP : Convert string to timestamp or datestamp before storing to database(MariaDB/MySQL)