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
+7.9k Swift : Convert (cast) String to Float
+8.2k Golang : HttpRouter multiplexer routing example
+22.4k Golang : How to read JPG(JPEG), GIF and PNG files ?
+10.7k Golang : Interfacing with PayPal's IPN(Instant Payment Notification) example
+10.5k Swift : Convert (cast) String to Integer
+6.6k Golang : Embedded or data bundling example
+23.9k Golang : Fix type interface{} has no field or no methods and type assertions example
+14.4k Golang : Recombine chunked files example
+5k Google : Block or disable caching of your website content
+18.6k Golang : Get download file size
+10.6k Golang : Get local time and equivalent time in different time zone
+7.9k Javascript : Put image into Chrome browser's console