GIF libraries
Open-source libraries that decode and encode GIF files. Every image library reads the first frame; the differences are in animation: whether the library returns all frames, whether it composites them on the canvas (applying disposal methods) or gives you the raw sub-rectangles, and whether it can write animated GIFs with delays and a loop count. Writing a good GIF also needs color quantization from RGB to a 256-color palette, which some libraries do well and some leave to you.
| Language | Library | Read | Write | Notes |
|---|---|---|---|---|
| C/C++ | GIFLIB | yes | yes | animation: read and write; reference C library, raw frames, no quantizer |
| C/C++ | stb_image | yes | no | animation: read (composited); single header, public domain |
| C# | ImageSharp | yes | yes | animation: read and write; pure managed code; Six Labors Split License |
| C# | Magick.NET | yes | yes | animation: read and write; ImageMagick for .NET, coalesce and optimize |
| Java | ImageIO | yes | yes | animation: read and write (raw frames); built into the JDK, metadata tree for delays |
| Go | image/gif | yes | yes | animation: read and write (raw frames); standard library |
| Python | Pillow | yes | yes | animation: read and write (composited); the standard Python imaging library |
| Ruby | ruby-vips | yes | yes | animation: read and write; libvips with cgif and libimagequant |
| Ruby | MiniMagick | yes | yes | animation: read and write; wraps ImageMagick command line |
| Rust | gif | yes | yes | animation: read and write (raw frames); pure Rust, streaming, used by image |
| Rust | image | yes | yes | animation: read and write (composited); high-level, many formats |
| PHP | GD | yes | yes | no animation (first frame only); bundled with PHP |
| PHP | Imagick | yes | yes | animation: read and write; ImageMagick extension |
| PHP | Intervention Image | yes | yes | animation: read and write; animated GIF with GD or Imagick drivers |
By language#
- GIF libraries for C/C++ Open-source C/C++ libraries to read and write GIF and animated GIF: GIFLIB and stb_image. Comparison, when to use each, and code examples.
- GIF libraries for C# Open-source .NET libraries to read and write GIF and animated GIF: ImageSharp and Magick.NET. Comparison, when to use each, and code examples.
- GIF libraries for Java Open-source Java libraries to read and write GIF and animated GIF: the built-in ImageIO with its GIF metadata format. Code examples for frames, delays.
- GIF libraries for Go Open-source Go libraries to read and write GIF and animated GIF: the standard image/gif package. Code examples for frames, delays, looping and palettes.
- GIF libraries for Python Open-source Python libraries to read and write GIF and animated GIF: Pillow. Code examples for frames, durations, looping, palettes and optimization.
- GIF libraries for Ruby Open-source Ruby libraries to read and write GIF and animated GIF: ruby-vips and MiniMagick. Comparison, when to use each, and code examples.
- GIF libraries for Rust Open-source Rust crates to read and write GIF and animated GIF: gif and image. Comparison, when to use each, and code examples.
- GIF libraries for PHP Open-source PHP libraries to read and write GIF and animated GIF: GD, Imagick and Intervention Image. Comparison, when to use each, and code examples.