Posted
技术标签:
【中文标题】如何使用 golang 压缩和调整 gif【英文标题】:how to use golang compress and resize a gif 【发布时间】:2019-06-07 00:01:14 【问题描述】:是否有使用 golang 压缩和调整 gif 大小的方法或库?
ps:我试过bimg,但是不支持gif。
【问题讨论】:
bimg 通过 C 绑定使用 libvips。你的 lipvbs 是否支持 gif 构建? 【参考方案1】:见文档https://golang.org/pkg/image/gif/#GIF
func DecodeAll(r io.Reader) (*GIF, error)
现在你可以得到一个 GIF 结构
type GIF struct
Image []*image.Paletted // The successive images.
然后您可以在 GIF 中调整每个图像的大小。
for _,img:=range gif.Image
resize(img)
PS:image.Paletted实现了image.Image,所以可以使用https://github.com/nfnt/resize来调整Image的大小。
【讨论】:
resize
https://golang.org/pkg/image/#Imagehttps://golang.org/pkg/image/#Paletted
【参考方案2】:
我从未使用过,但我认为您可以使用 std 库(导入“image/gif”)读取/写入 GIF。然后使用“resize”之类的东西来调整大小(参见Go Resizing Images)
【讨论】:
以上是关于如何使用 golang 压缩和调整 gif的主要内容,如果未能解决你的问题,请参考以下文章