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
+9.2k Golang : Create and shuffle deck of cards example
+6.6k Golang : Totalize or add-up an array or slice example
+5.4k Golang : Reclaim memory occupied by make() example
+14.8k Golang : Adding XML attributes to xml data or use attribute to differentiate a common tag name
+7.8k Golang : Getting Echo framework StartAutoTLS to work
+13.2k Golang : Skip blank/empty lines in CSV file and trim whitespaces example
+15.8k Golang : Get digits from integer before and after given position example
+4.9k Python : Find out the variable type and determine the type with simple test
+12.1k Golang : Split strings into command line arguments
+10.5k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters
+15.6k Golang : ROT47 (Caesar cipher by 47 characters) example