Created
October 2, 2013 04:11
-
-
Save gongo/6789068 to your computer and use it in GitHub Desktop.
github.com/boppreh/gifencoder を使って Animation GIF が作れるかテスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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