Golang image.gif.EncodeAll, GIF and DecodeAll example
package image/gif
Golang image.gif.EncodeAll, GIF and DecodeAll usage example
package main
import (
"fmt"
"image/gif"
"os"
)
func main() {
inputFile, err := os.Open("input.gif")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer inputFile.Close()
g, err := gif.DecodeAll(inputFile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Loop count : ", g.LoopCount)
fmt.Println("Delay : ", g.Delay[:])
fmt.Println("Image : ", g.Image[:])
outputFile, err := os.Create("output.gif")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer outputFile.Close()
// ok, write out the data into the new GIF file
err = gif.EncodeAll(outputFile, g)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println("Generated image to output.gif \n")
}
Output(sample) :
Loop count : 0
Delay : [11 11 11 11 11 11 11 11 11 11 11 11 11 11]
Image : [0x208214060 0x208214120 0x2082141e0 0x2082142a0 0x208214360 0x208214420 0x2082144e0 0x2082145a0 0x208214660 0x208214720 0x2082147e0 0x2082148a0 0x208214960 0x208214a20]
Generated image to output.gif
References :
http://golang.org/pkg/image/gif/#EncodeAll
Advertisement
Something interesting
Tutorials
+24.6k Golang : How to validate URL the right way
+12.7k Android Studio : Highlight ImageButton when pressed on example
+9.5k Mac OSX : Get a process/daemon status information
+11k How to test Facebook App on localhost ?
+11k Golang : Replace a parameter's value inside a configuration file example
+9.2k Golang : Generate Codabar
+7.4k Golang : Scanf function weird error in Windows
+33.6k Golang : How to check if slice or array is empty?
+20.8k Golang : Convert date string to variants of time.Time type examples
+15.6k Golang : Validate hostname
+21.7k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+19.3k Golang : Get host name or domain name from IP address