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
+7.7k Golang : How to execute code at certain day, hour and minute?
+8.2k Prevent Write failed: Broken pipe problem during ssh session with screen command
+5.4k Golang : What is StructTag and how to get StructTag's value?
+10k Golang : Get escape characters \u form from unicode characters
+13.9k Golang : convert(cast) string to float value
+39k Golang : How to iterate over a []string(array)
+9.6k Golang : How to generate Code 39 barcode?
+6.7k Golang : Output or print out JSON stream/encoded data
+8.8k Yum Error: no such table: packages
+19.3k Golang : Calculate entire request body length during run time
+9.1k Golang : io.Reader causing panic: runtime error: invalid memory address or nil pointer dereference
+7.2k Golang : Check if one string(rune) is permutation of another string(rune)