gif

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package gif implements a GIF image decoder and encoder.

The GIF specification is at https://www.w3.org/Graphics/GIF/spec-gif89a.txt.

Index

Constants

View Source
const (
	DisposalNone       = 0x01
	DisposalBackground = 0x02
	DisposalPrevious   = 0x03
)

Disposal Methods.

Variables

This section is empty.

Functions

func Decode

func Decode(r io.Reader) (image.Image, error)

Decode reads a GIF image from r and returns the first embedded image as an image.Image.

func DecodeConfig

func DecodeConfig(r io.Reader) (image.Config, error)

DecodeConfig returns the global color model and dimensions of a GIF image without decoding the entire image.

func DecodeExtended

func DecodeExtended(ctx context.Context, r io.Reader, opts ...image.ReadOption) (image.Image, image.Metadata, error)

func Encode

func Encode(w io.Writer, m image.Image, o *Options) error

Encode writes the Image m to w in GIF format.

func EncodeAll

func EncodeAll(w io.Writer, g *GIF) error

EncodeAll writes the images in g to w in GIF format with the given loop count and delay between frames.

Types

type Extension

type Extension struct {
	AuthCode string
	Body     []byte
}

Extension holds the contents of an extension.

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 controls the number of times an animation will be
	// restarted during display.
	// A LoopCount of 0 means to loop forever.
	// A LoopCount of -1 means to show each frame only once.
	// Otherwise, the animation is looped LoopCount+1 times.
	LoopCount int
	// 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.

func DecodeAll

func DecodeAll(r io.Reader) (*GIF, error)

DecodeAll reads a GIF image from r and returns the sequential frames and timing information.

type Metadata

type Metadata struct {

	// Comments holds the contents of any comment extension blocks.
	Comments []string
	// Extensions is a map that holds any extension data we can't deal with
	Extensions map[string]*Extension

	// Width holds the image width, in pixels
	Width int
	// Height holds the image height, in pixels
	Height int
	// ColorModel holds the image color models
	ColorModel color.Model
	// contains filtered or unexported fields
}

func (*Metadata) GetConfig

func (m *Metadata) GetConfig() image.Config

func (*Metadata) ImageMetadataFormat

func (m *Metadata) ImageMetadataFormat() string

ImageMetadataFormat returns the image type for this metadata.

func (*Metadata) IsImageWriteOption

func (m *Metadata) IsImageWriteOption()

IsImageWriteOption lets a gif metadata struct be passed as a write option to EncodeExtended.

func (*Metadata) SetXMP

func (m *Metadata) SetXMP(x *metadata.XMP)

SetXmp replaces the XMP information associated with the metadata object.

func (*Metadata) XMP

func (m *Metadata) XMP(ctx context.Context, opt ...image.ReadOption) (*metadata.XMP, error)

Xmp returns the xmp information associated with the metadata object. If there is no xmp information then it will return nil. The returned xmp structure will still be associated with its parent metadata object, and changes to it will be persistent.

Note that the xmp information may be decoded lazily.

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.

func (*Options) IsImageWriteOption

func (_ *Options) IsImageWriteOption()

GIF options are metadata write options.

type ReadOption

type ReadOption struct {
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL