英文:
go - Encoding gif image.Image
问题
image/jpeg和image/png包有Decode和Encode函数,用于读取和写入jpeg和png图像,但是image/gif包没有这些函数,只有Decode和DecodeAll函数。
那么,有什么办法可以将gif图像.Image编码为io.Writer吗?
英文:
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?
答案1
得分: 8
Go标准库中没有包含GIF编码器。
我认为你最好的选择是使用cgo与一个C库进行接口交互,该库可以编码GIF。giflib看起来相当简单。
或者,你可以将giflib的相关部分移植到Go中,并将其提交给标准库。
GIF编码不普及的一个历史原因是它使用的LZW压缩受到了专利的保护。然而,这些专利现在已经过期,所以除了GIF不再像以前那样流行之外,没有理由不在标准库中包含一个压缩器!
英文:
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!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论