💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# package gif `import "image/gif"` gif包实现了gif文件的编码器和解码器。gif格式参见:[http://www.w3.org/Graphics/GIF/spec-gif89a.txt](http://www.w3.org/Graphics/GIF/spec-gif89a.txt) ## Index * [type Options](#Options) * [func Decode(r io.Reader) (image.Image, error)](#Decode) * [func DecodeConfig(r io.Reader) (image.Config, error)](#DecodeConfig) * [func Encode(w io.Writer, m image.Image, o \*Options) error](#Encode) * [type GIF](#GIF) * [func DecodeAll(r io.Reader) (\*GIF, error)](#DecodeAll) * [func EncodeAll(w io.Writer, g \*GIF) error](#EncodeAll) ## type [Options](https://github.com/golang/go/blob/master/src/image/gif/writer.go#L246 "View Source") ``` type Options struct { // NumColors是图像中的最多颜色数,范围[1, 256] NumColors int // Quantizer用于生成NumColors大小的调色板,为nil时默认使用palette.Plan9 Quantizer draw.Quantizer // Drawer用于将图像写入期望的调色板格式的图像,为nil时会使用draw.FloydSteinberg Drawer draw.Drawer } ``` Options是编码参数。 ## func [Decode](https://github.com/golang/go/blob/master/src/image/gif/reader.go#L414 "View Source") ``` func Decode(r io.Reader) (image.Image, error) ``` 从文件流解码并返回GIF文件中的第一幅图像。 ## func [DecodeConfig](https://github.com/golang/go/blob/master/src/image/gif/reader.go#L446 "View Source") ``` func DecodeConfig(r io.Reader) (image.Config, error) ``` 返回GIF图像的色彩模型和尺寸;函数不会解码整个图像文件。 ## func [Encode](https://github.com/golang/go/blob/master/src/image/gif/writer.go#L291 "View Source") ``` func Encode(w io.Writer, m image.Image, o *Options) error ``` 函数将图像以GIF格式写入w中。 ## type [GIF](https://github.com/golang/go/blob/master/src/image/gif/reader.go#L423 "View Source") ``` type GIF struct { Image []*image.Paletted // 连续的图像 Delay []int // 每一帧延迟时间,单位是0.01s LoopCount int // 总的循环时间 } ``` GIF类型代表可能保存在GIF文件里的多幅图像。 ### func [DecodeAll](https://github.com/golang/go/blob/master/src/image/gif/reader.go#L431 "View Source") ``` func DecodeAll(r io.Reader) (*GIF, error) ``` 函数从r中读取一个GIF格式文件;返回值中包含了连续的图帧和时间信息。 ### func [EncodeAll](https://github.com/golang/go/blob/master/src/image/gif/writer.go#L262 "View Source") ``` func EncodeAll(w io.Writer, g *GIF) error ``` 函数将g中所有的图像按指定的每帧延迟和累计循环时间写入w中。