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 :
Advertisement
Something interesting
Tutorials
+18k Golang : Get all upper case or lower case characters from string example
+31.9k Golang : Convert an image file to []byte
+14.8k Golang : Find commonalities in two slices or arrays example
+11.1k Golang : How to determine a prime number?
+13.4k Golang : Increment string example
+10.6k Golang : ISO8601 Duration Parser example
+10.1k Golang : How to tokenize source code with text/scanner package?
+16.4k Golang : Convert slice to array
+5.3k Golang : Generate Interleaved 2 inch by 5 inch barcode
+8.3k Useful methods to access blocked websites
+8.3k Golang : Auto-generate reply email with text/template package
+21.8k Golang : How to reverse slice or array elements order