File Exchange

image thumbnail

Tools to read and write animated gif files

version (7.3 KB) by DGM
Functions to read and write animated gifs to and from 4-D RGB image arrays


Updated 18 Jun 2018

View License

These functions can be used to read and write animated gifs. They are intended for use with 4-D image arrays of various type. Supported types include RGB/RGBA arrays, as well as indexed images. Indexed mages with transparent content can be specified by a corresponding vector of indices, or by simply appending an alpha channel to the image array itself. When writing, colormaps, transparency, and disposal method can be specified per-frame or globally.
Optional functionality requires the use of imagemagick and is exclusively intended to work in a *nix environment, but default settings should work on other systems. I have no intention of modifying this to be more robust in that aspect.
reads all frames of an animated gif into a 4-D image array
Write image stack to an animated gif

Cite As

DGM (2020). Tools to read and write animated gif files (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)


Jack: That sounds reasonable. I've added that to the todo list.

Great gifwrite(). How about having a frame range for gifread() so one can efficiently test methods used on large GIFs, for example?


fixed a bug for logical & single-frame images (gifwrite)

fixed description

Fixed some handling of TCIDX, some documentation errors.
Better support for importing transparent images with specified disposal methods

forgot to include MIMT dependencies

removed mapping toolbox dependency
added class flexibility as well as some indexed image, & transparency support

added automatic expansion on dim 3 and a bit of input class flexibility to GIFWRITE()

added thumbnail image

fixed archive problem again

fixed archive mistake

changed both functions to utilize /dev/shm instead of hard disk for temporary file creation when using optional 'imagemagick' modes; also increased speed and quality of 'imagemagick' mode in gifwrite.m

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux