wkzq
wkzq

Reputation: 333

how to use golang compress and resize a gif

Is there has method or lib to compress and resize a gif use golang?

ps: I was tried bimg, but it not support gif.

Upvotes: 5

Views: 3760

Answers (2)

Billy Yuan
Billy Yuan

Reputation: 1295

see doc https://golang.org/pkg/image/gif/#GIF

func DecodeAll(r io.Reader) (*GIF, error)

now you can get a GIF struct

type GIF struct {
        Image []*image.Paletted // The successive images.

then you can resize each of Image in GIF.

for _,img:=range gif.Image{
    resize(img)
}

PS: image.Paletted implemented image.Image, so you can use https://github.com/nfnt/resize to resize the Image.

Upvotes: 4

Andrew W. Phillips
Andrew W. Phillips

Reputation: 3601

I've never used but I think you can read/write GIFs using the std library (import "image/gif"). Then resize using something like "resize" (see Go Resizing Images)

Upvotes: -1

Related Questions