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
+10.5k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+8.8k Golang : Executing and evaluating nested loop in html template
+12.1k Golang : Perform sanity checks on filename example
+10.6k Golang : Simple File Server
+17.5k Golang : Linked list example
+5.2k JavaScript/JQuery : Redirect page examples
+9.7k Random number generation with crypto/rand in Go
+8.8k Golang : HTTP Routing with Goji example
+9.2k Golang : Write multiple lines or divide string into multiple lines
+10.5k Generate Random number with math/rand in Go
+7.9k Javascript : Put image into Chrome browser's console