DEV Community

ntop
ntop

Posted on

Write a GIF player with Golang

I just wrote a gif player with golang (less then 200 lines code). I use MAC a lot, but it can't play gif like windows, so this project come out.

It's a Golang project, also a korok project. The core code is little:

func main() {
    gfile := flag.Arg(0)
    // decode !
    gp, err := Load(gfile)
    if err != nil {
        log.Fatal(err)
    }
    w, h := gp.Size()
    options := korok.Options{
        Title: "Gif Player",
        Width:w,
        Height:h,
    }
    korok.Run(&options, &MainScene{p: gp})
}
Enter fullscreen mode Exit fullscreen mode

Gif decoding use Golong's gif module, the ui is setup with korok engine's GUI system. In fact, just one method is used:

gui.Image(1, m.img, nil)
Enter fullscreen mode Exit fullscreen mode

This API will draw a Texture at (0,0) of screen.

I have uploaded the project to Github: https://github.com/ntop001/xgif

About korok: it's component based 2d game engine in Golang, include a concise gui system. I use it to write some small tools. See: https://korok.io/

Top comments (0)