Golang image.RegisterFormat function example
package image
func RegisterFormat(name, magic string, decode func(io.Reader) (Image, error), decodeConfig func(io.Reader) (Config, error))
RegisterFormat registers an image format for use by Decode. Name is the name of the format, like "jpeg" or "png". Magic is the magic prefix that identifies the format's encoding. The magic string can contain "?" wildcards that each match any one byte. Decode is the function that decodes the encoded image. DecodeConfig is the function that decodes just its configuration.
Golang image.RegisterFormat function usage example
import (
"image"
"image/gif"
"image/jpeg"
"image/png"
)
func init() {
image.RegisterFormat("jpeg", "jpeg", jpeg.Decode, jpeg.DecodeConfig)
image.RegisterFormat("png", "png", png.Decode, png.DecodeConfig)
image.RegisterFormat("gif", "gif", gif.Decode, gif.DecodeConfig)
}
Reference :
Advertisement
Something interesting
Tutorials
+9.6k Golang : Bubble sort example
+28.9k Golang : Generate random string
+19.8k Golang : How to get time zone and load different time zone?
+4.1k Swift : Convert (cast) Float to Int or Int32 value
+7.1k Golang : Emulate NumPy way of creating matrix example
+9.1k Golang : Wait and sync.WaitGroup example
+4.4k PHP : Fix Call to undefined function curl_init() error
+4k Google : Block or disable caching of your website content
+44.1k Golang : Read tab delimited file with encoding/csv package
+13.1k Golang : Overwrite previous output with count down timer
+12k Golang : Image to ASCII art example
+7.2k Golang : Metaprogramming example of wrapping a function