Documentation ¶
Overview ¶
Package gif implements a GIF image decoder and encoder.
The GIF specification is at http://www.w3.org/Graphics/GIF/spec-gif89a.txt.
Index ¶
Examples ¶
Constants ¶
const ( DisposalNone = 0x01 DisposalBackground = 0x02 DisposalPrevious = 0x03 )
Disposal Methods.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode reads a GIF image from r and returns the first embedded image as an image.Image.
func DecodeConfig ¶
DecodeConfig returns the global color model and dimensions of a GIF image without decoding the entire image.
Types ¶
type FrameDecoder ¶
type FrameDecoder struct {
// contains filtered or unexported fields
}
FrameDecoder provides a convenient interface for frame-by-frame decoding of a GIF image.
Example ¶
package main import ( "fmt" "os" "github.com/artyom/image/gif" ) func main() { f, err := os.Open("../testdata/video-001.gif") if err != nil { fmt.Println(err) return } defer f.Close() dec := gif.NewFrameDecoder(f) for dec.Next() { img, delay, disposal := dec.Frame() fmt.Printf("%T, %d, %v\n", img, delay, disposal) } if err := dec.Err(); err != nil { fmt.Println(err) return } }
Output: *image.Paletted, 0, 0
func NewFrameDecoder ¶
func NewFrameDecoder(r io.Reader) *FrameDecoder
NewFrameDecoder returns a new FrameDecoder to read from r.
func (*FrameDecoder) BackgroundIndex ¶
func (fd *FrameDecoder) BackgroundIndex() byte
BackgroundIndex returns background index if known. It is usually known after decoding the first frame – after the first Next() call.
func (*FrameDecoder) Err ¶
func (fd *FrameDecoder) Err() error
Err returns first error encountered by the FrameDecoder
func (*FrameDecoder) Frame ¶
func (fd *FrameDecoder) Frame() (*image.Paletted, int, byte)
Frame returns most recent frame decoded by a call to Next. Extra attributes are delay time in 100ths of a second and disposal method — see GIF.Delay and GIF.Disposal documentation.
func (*FrameDecoder) LoopCount ¶
func (fd *FrameDecoder) LoopCount() int
LoopCount returns loop count if known. It is usually known after decoding the first frame – after the first Next() call.
func (*FrameDecoder) Next ¶
func (fd *FrameDecoder) Next() bool
Next decodes the next frame. It returns false when decoding stops, either by reaching the end of the input or an error. After Next returns false, the Err method will return any error that occurred during decoding.
type FrameEncoder ¶
type FrameEncoder struct {
// contains filtered or unexported fields
}
FrameEncoder provides a convenient interface for frame-by-frame encoding of a GIF image.
func NewFrameEncoder ¶
NewFrameEncoder returns a new FrameEncoder writing to w.
func (*FrameEncoder) Close ¶
func (f *FrameEncoder) Close() error
Close writes GIF format trailer and flushes output.
func (*FrameEncoder) EncodeFrame ¶
EncodeFrame writes a single frame.
type GIF ¶
type GIF struct { Image []*image.Paletted // The successive images. Delay []int // The successive delay times, one per frame, in 100ths of a second. LoopCount int // The loop count. // Disposal is the successive disposal methods, one per frame. For // backwards compatibility, a nil Disposal is valid to pass to EncodeAll, // and implies that each frame's disposal method is 0 (no disposal // specified). Disposal []byte // Config is the global color table (palette), width and height. A nil or // empty-color.Palette Config.ColorModel means that each frame has its own // color table and there is no global color table. Each frame's bounds must // be within the rectangle defined by the two points (0, 0) and // (Config.Width, Config.Height). // // For backwards compatibility, a zero-valued Config is valid to pass to // EncodeAll, and implies that the overall GIF's width and height equals // the first frame's bounds' Rectangle.Max point. Config image.Config // BackgroundIndex is the background index in the global color table, for // use with the DisposalBackground disposal method. BackgroundIndex byte }
GIF represents the possibly multiple images stored in a GIF file.
type Options ¶
type Options struct { // NumColors is the maximum number of colors used in the image. // It ranges from 1 to 256. NumColors int // Quantizer is used to produce a palette with size NumColors. // palette.Plan9 is used in place of a nil Quantizer. Quantizer draw.Quantizer // Drawer is used to convert the source image to the desired palette. // draw.FloydSteinberg is used in place of a nil Drawer. Drawer draw.Drawer }
Options are the encoding parameters.