Golang image.Config type example
package image
type Config struct { ColorModel color.Model Width, Height int }
Config holds an image's color model and dimensions.
Golang image.Config type usage example
package main
import (
"fmt"
"image"
"image/png"
"os"
)
func init() {
// without this register .. At(), Bounds() functions will
// caused memory pointer error!!
image.RegisterFormat("png", "png", png.Decode, png.DecodeConfig)
}
func main() {
imgfile, err := os.Open("./img.png")
if err != nil {
fmt.Println("img.png file not found!")
os.Exit(1)
}
defer imgfile.Close()
img, _, err := image.Decode(imgfile)
bounds := img.Bounds()
width := bounds.Max.X
height := bounds.Max.Y
fmt.Println("Width : ", width)
fmt.Println("Height : ", height)
colormodel := img.ColorModel()
ic := image.Config{colormodel, width, height}
//test
fmt.Println(ic.Width) // Width starts with capital letter
}
References :
Advertisement
Something interesting
Tutorials
+48.5k Golang : Upload file from web browser to server
+12k Golang : Decompress zlib file example
+5.7k Get website traffic ranking with Similar Web or Alexa
+36.5k Golang : Save image to PNG, JPEG or GIF format.
+7.3k Golang : How to fix html/template : "somefile" is undefined error?
+11.5k Golang : Generate DSA private, public key and PEM files example
+18.7k Golang : convert int to string
+15.6k Golang : Validate hostname
+8.5k Golang : How to check variable or object type during runtime?
+13.9k Golang : How to check if a file is hidden?
+6.5k Golang : Spell checking with ispell example
+5k Golang : Get a list of crosses(instruments) available to trade from Oanda account