Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go - Encoding gif image.Image

Tags:

image

go

The image/jpeg and image/png packages have Decode and Encode functions that read and write jpeg and png images, but the image/gif package does not - only Decode and DecodeAll.

Any ideas then, on how to encode a gif image.Image into an io.Writer?

like image 944
user81779 Avatar asked Jun 19 '13 06:06

user81779


1 Answers

The Go standard library doesn't include a GIF encoder.

I think your best bet will be to use cgo to interface with a C library which encodes GIFs. giflib looks reasonably straight forward.

Alternatively you could port the relevant parts of giflib to go and submit them to the standard library.

There is a historical reason why GIF encoding isn't widespread - it was covered by patents on the LZW compression used. However those patents have now expired so there is no reason not to have a compressor in the standard library other than the fact that GIFs aren't as popular as they used to be!

like image 81
Nick Craig-Wood Avatar answered Sep 30 '22 03:09

Nick Craig-Wood