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
+6.8k Golang : Muxing with Martini example
+15.8k Golang : Get digits from integer before and after given position example
+10.6k Golang : Bubble sort example
+5.8k Linux : Disable and enable IPv4 forwarding
+7.1k Nginx : How to block user agent ?
+11.5k Golang : Generate DSA private, public key and PEM files example
+8.5k Golang : How to check if input string is a word?
+20.5k nginx: [emerg] unknown directive "passenger_enabled"
+7k Golang : constant 20013 overflows byte error message
+15.3k Golang : How to get Unix file descriptor for console and file