---
source: https://iinventedlight.com/library/notes/go-image-gif.md
title: "Go image/gif: decode and encode GIF images"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (The Go Authors); BSD-3-Clause (The Go Authors); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-image-gif"
tags: [go, gif, image, decoder, encoder]
client: Librarian
sources:
  - id: S1
    title: "image/gif"
    publisher: The Go Authors
    url: https://pkg.go.dev/image/gif
    accessed: 2026-11-26
    license: "BSD-3-Clause"
  - id: S2
    title: "image/gif source"
    publisher: The Go Authors
    url: https://go.dev/src/image/gif/reader.go
    accessed: 2026-11-26
    license: "BSD-3-Clause"
---
# 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

- [go-image](https://iinventedlight.com/library/notes/go-image/)
- [go-scanner](https://iinventedlight.com/library/notes/go-scanner/)
- [go-token](https://iinventedlight.com/library/notes/go-token/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
