Skip to content

Instantly share code, notes, and snippets.

@gongo
Created October 2, 2013 04:11
Show Gist options
  • Save gongo/6789068 to your computer and use it in GitHub Desktop.
Save gongo/6789068 to your computer and use it in GitHub Desktop.
github.com/boppreh/gifencoder を使って Animation GIF が作れるかテスト
package main
import (
"github.com/boppreh/gifencoder"
"image"
"image/gif"
"io/ioutil"
"os"
)
func readGIF(filename string) (*gif.GIF, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer f.Close()
return gif.DecodeAll(f)
}
func main() {
frames := []string{
"./01.gif",
"./02.gif",
"./03.gif",
}
g := &gif.GIF{
Image: make([]*image.Paletted, len(frames)),
Delay: make([]int, len(frames)),
LoopCount: 0,
}
for i, f := range frames {
m, err := readGIF(f)
if err != nil {
panic(err)
}
g.Image[i] = m.Image[0]
g.Delay[i] = 2
}
file, _ := ioutil.TempFile("", "karaage")
defer file.Close()
if err := gifencoder.EncodeAll(file, g); err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment