Go image/gif: decode and encode GIF images
Answer: Package image/gif implements a GIF image decoder and encoder.
Decoding
Decode reads a GIF from a reader and returns only the first embedded image as an image.Image.
DecodeAll reads a GIF and can return more than one embedded image.
DecodeConfig reads dimensions and other configuration without decoding the full image data.
For untrusted input, call DecodeConfig first and check the dimensions before Decode or DecodeAll, as the image package security notes describe.
Encoding and disposal
Encode writes a single image. EncodeAll writes a GIF from a GIF value.
Disposal constants include DisposalNone, DisposalBackground, and DisposalPrevious.
See also
Claims
- id: C1 claim: The package implements a GIF decoder and encoder. source: S1 evidence: "Package gif implements a GIF image decoder and encoder."
- id: C2 claim: Decode returns the first embedded image. source: S1 evidence: "returns the first embedded image"
- id: C3 claim: DisposalNone is defined as 0x01. source: S2 evidence: "DisposalNone = 0x01"
Sources
- [S1] image/gif. The Go Authors. https://pkg.go.dev/image/gif . License: BSD-3-Clause. Accessed 2026-11-26.
- [S2] image/gif source. The Go Authors. https://go.dev/src/image/gif/reader.go . License: BSD-3-Clause. Accessed 2026-11-26.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, image/gif; The Go Authors, image/gif source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: The Go Authors, image/gif; The Go Authors, image/gif source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go image/gif: decode and encode GIF images." iinventedlight Library, iil:note:1xfz4rxf, version of 2026-11-26. https://iinventedlight.com/library/notes/go-image-gif/. License: CC-BY-4.0.
@misc{iil_note_1xfz4rxf,
author = {{iinventedlight}},
title = {{Go image/gif: decode and encode GIF images}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-26},
url = {https://iinventedlight.com/library/notes/go-image-gif/},
note = {Permanent ID iil:note:1xfz4rxf. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-image-gif.schema.json (schema; CC-BY-4.0)
- go-image-gif.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-image-gif.md.