This is documentation for Mathematica 6, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)
Mathematica Import/Export Format

GIF (.gif)

Registered MIME type: image/gif
GIF raster image format.
Commonly used for static and animated graphics on the web.
GIF is an acronym for Graphics Interchange Format.
Binary format.
Uses LZW lossless compression after restriction to an 8-bit color palette.
Supports transparency.
Developed in 1987 by CompuServe.
  • Import and Export fully support the GIF89a standard for both static and animated GIF images.
  • Import["file.gif"] imports a GIF file, returning a single graphics object or a list of animation frames.
  • Export["file.gif", expr] exports graphics or any other expression as an image to a GIF file.
  • Export["file.gif", {g1, g2, ...}] exports a list of graphics as an animation.
  • Import["file.gif"] returns an expression of the form Graphics[Raster[data], opts], where data is an array of color indices.
  • Export["file.gif", expr] creates a GIF image with the same image size as the displayed form of expr.
  • Because GIF is a raster image format, all fonts are rasterized on export.
  • Import["file.gif", elem] imports the specified element from a GIF file.
  • Import["file.gif", {elem, suba, subb, ...}] imports a subelement.
  • Import["file.gif", {{elem1, elem2, ...}}] imports multiple elements.
  • The import format can be specified with Import["file", "GIF"] or Import["file", {"GIF", elem, ...}].
  • Export["file.gif", expr, elem] creates a GIF file by treating expr as specifying element elem.
  • Export["file.gif", {expr1, expr2, ...}, {{elem1, elem2, ...}}] treats each expri as specifying the corresponding elemi.
  • Export["file.gif", expr, opt1->val1, ...] exports expr with the specified option elements taken to have the specified values.
  • Export["file.gif", {elem1->expr1, elem2->expr2, ...}, "Rules"] uses rules to specify the elements to be exported.
  • See the reference pages for full general information on Import and Export.
  • In the notebook front end, Insert ► Picture and the Open menu allow import of a GIF file into a cell.
  • Save Selection As exports the selected part of a notebook as a GIF file.
"Elements"list of elements and options available in this file
"Rules"full list of rules for each element and option
"Options"list of rules for options, properties, and settings
  • Data representation elements:
"Animation"animated GIF represented as an animation object
"Graphics"graphics representing a static GIF or the first frame of an animated GIF
"GraphicsList"frames of an animated GIF as a list of graphics
  • Import by default uses "Graphics" for an ordinary static GIF, and "GraphicsList" for an animated GIF.
  • Import of an animated GIF with element "Graphics" gives the first frame of the animation.
  • Export by default generates an animated GIF if the expression supplied is a list of Graphics objects, and a static GIF otherwise.
  • Export with element "Graphics" always generates a static GIF.
"Background"background color shown in transparent image regions
"BitDepth"bits used to represent each color channel in the file
"ImageCount"number of frames in an animated GIF
  • Data representation elements for a static GIF or the frames of animated GIF files:
"ColorMap"color reduction palette
"Data"array of RGB color values
"GlobalColorMap"color reduction palette used by all frames, given as a list of RGBColor objects
"GrayLevels"array of normalized gray-level values
"ImageSize"overall image size
"RawData"array of color map indices
"RGBColorArray"array of RGBColor objects
  • For animated GIFs, the above data representation elements are taken to be lists of the respective expressions.
  • Metadata element:
"Comments"user comments
  • General options:
BackgroundAutomaticbackground color shown in transparent image regions
ImageSizeAutomaticoverall image size
"ImageTopOrientation"Toporientation of the image as stored in the file
"DitheringMethod""FloydSteinberg"dithering algorithm used for generating the color-reduction table
"TransparentColor"Automaticcolor to be interpreted as transparent
  • Export["file.gif", expr, "TransparentColor"->White] creates a GIF file in which all white pixels of the original image are taken to be transparent.
  • Possible settings for "DitheringMethod" are "FloydSteinberg" or None.
  • Detailed properties and settings for animated GIF:
"DisplayDurations"Automaticdisplay duration for each frame in seconds
"Interlaced"Falsewhether the graphics are stored in interlaced format, allowing progressive rendering
AnimationRepetitions1how many times the animation plays before stopping
  • GIF supports color palettes of at most 256 colors, always storing colors at a resolution of 8 bits per color channel.
  • "DisplayDurations"->{d1, d2, ...} specifies the display durations for each frame in an animated GIF. If the list of display durations is shorter than the number of frames, the sequence is repeated as necessary.
  • With the default setting "DisplayDurations"-> Automatic, the display time will vary on different viewer applications.
npositive integer, specifying how many times the animation should be played
Infinityanimation is repeated indefinitely