gif

package
v1.26.2 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

gifパッケージは、GIF画像のデコーダとエンコーダを実装します。

GIFの仕様は https://www.w3.org/Graphics/GIF/spec-gif89a.txt にあります。

Index

Constants

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

廃棄方法。

Variables

This section is empty.

Functions

func Decode

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

Decodeは、rからGIF画像を読み取り、最初の埋め込み画像を image.Image として返します。

func DecodeConfig

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

DecodeConfigは、画像全体をデコードすることなく、GIF画像のグローバルカラーモデルと 寸法を返します。

func Encode added in v1.2.0

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

Encodeは、GIF形式で画像mをwに書き込みます。

func EncodeAll added in v1.2.0

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

EncodeAllは、指定されたループカウントとフレーム間の遅延で、 GIF形式のwにgの画像を書き込みます。

Types

type GIF

type GIF struct {
	Image []*image.Paletted
	Delay []int
	// LoopCountは、表示中にアニメーションが再開される回数を制御します。
	// LoopCountが0の場合、無限にループします。
	// LoopCountが-1の場合、各フレームを一度だけ表示します。
	// それ以外の場合、アニメーションはLoopCount+1回ループします。
	LoopCount int
	// Disposalは、フレームごとの連続した廃棄方法です。後方互換性のために、
	// nil DisposalはEncodeAllに渡すことが有効であり、それぞれのフレームの廃棄方法が
	// 0(指定なしの廃棄)であることを意味します。
	Disposal []byte
	// Configは、グローバルカラーテーブル(パレット)、幅、高さです。nilまたは
	// 空のcolor.Palette Config.ColorModelは、各フレームが独自の
	// カラーテーブルを持ち、グローバルカラーテーブルがないことを意味します。各フレームの範囲は、
	// 二つの点 (0, 0) と (Config.Width, Config.Height) で定義される
	// 矩形内になければなりません。
	//
	// 後方互換性のため、ゼロ値のConfigはEncodeAllに渡すことが有効であり、
	// 全体のGIFの幅と高さが最初のフレームの範囲のRectangle.Max点と等しいことを意味します。
	Config image.Config
	// BackgroundIndexは、DisposalBackground廃棄方法で使用するための、
	// グローバルカラーテーブル内の背景インデックスです。
	BackgroundIndex byte
}

GIFは、GIFファイルに保存されている可能性のある複数の画像を表します。

func DecodeAll

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

DecodeAllは、rからGIF画像を読み取り、連続するフレームとタイミング情報を返します。

type Options added in v1.2.0

type Options struct {
	// NumColorsは、画像で使用される色の最大数です。
	// 1から256までの範囲です。
	NumColors int

	// Quantizerは、NumColorsのサイズを持つパレットを生成するために使用されます。
	// Quantizerがnilの場合、代わりにpalette.Plan9が使用されます。
	Quantizer draw.Quantizer

	// Drawerは、ソース画像を所望のパレットに変換するために使用されます。
	// Drawerがnilの場合、代わりにdraw.FloydSteinbergが使用されます。
	Drawer draw.Drawer
}

Optionsは、エンコーディングパラメータです。

Jump to

Keyboard shortcuts

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