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
+10.2k Golang : Text file editor (accept input from screen and save to file)
+18.5k Golang : Set, Get and List environment variables
+20.2k Golang : Determine if directory is empty with os.File.Readdir() function
+21.8k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+13.6k Golang : Set image canvas or background to transparent
+5.2k Golang : Customize scanner.Scanner to treat dash as part of identifier
+9.3k Golang : Timeout example
+18k Golang : Get all upper case or lower case characters from string example
+15.8k Golang : Get digits from integer before and after given position example
+26.8k Golang : Find files by extension
+9.7k Golang : Detect number of active displays and the display's resolution
+12.3k Golang : Display list of countries and ISO codes