GIF (.gif)
Background & Context

-
- 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 & Export

- Import["file.gif"] imports a GIF file, returning a single Image object or a list of images.
- Import["file.gif",elem] imports the specified element from a GIF file.
- The import format can be specified with Import["file","GIF"] or Import["file",{"GIF",elem,…}].
- Export["file.gif",expr] exports graphics, images, or any other expression to GIF.
- Export["file.gif",{expr1,expr2,…}] exports a list of graphics or images as an animation.
- Export["file.gif",Manipulate[…]] exports an animated demonstration of a Manipulate object.
- When exporting Wolfram Language graphics or arbitrary expressions to GIF, the resulting image has the same raster size as its displayed form.
- Image objects are by default exported at their raster size.
- Because GIF is a raster image format, all fonts are rasterized on export.
- See the reference pages for full general information on Import and Export.
- ImportString and ExportString support the GIF format.
Import Elements



- General Import elements:
-
"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 "Data" array of RGB color values "Graphics" first frame of a GIF file, given as a Graphics object "GraphicsList" frames of an animated GIF as a list of Graphics objects "Image" first frame of a GIF file, given as an Image object "ImageList" frames of an animated GIF as a list of Image objects "RawData" array of color map indices {"Thumbnail",size} thumbnail of the first image (default size = Small) {"ThumbnailList",frames,size} a list of thumbnails (default frames=All, size=Small) - Import by default uses the "Image" element for a static GIF and "ImageList" for an animated GIF.
- Import of an animated GIF with element "Image" gives the first frame of the animation.
- Export by default generates an animated GIF if the expression supplied is a list of images or a Manipulate, and a static GIF otherwise.
- Export with element "Graphics" or "Image" always generates a static GIF.
- Advanced Import elements:
-
"AnimationRepetitions" how many times the animation is played before stopping "Background" background color shown in transparent image regions "BitDepth" bits used to represent each color channel in the file "Channels" the number of color channels used in the file "ColorMap" color reduction palette, given as a list of color values "ColorSpace" color encoding used in the file "Comments" user comments stored in the file "DisplayDurations" display durations of animation frames, given in seconds "DisposalOperation" disposal operation before creating the next frame "GlobalColorMap" color palette used by default for individual animation frames "ImageCount" number of frames in an animated GIF "ImageSize" overall image size "Summary" summary of the file "SummarySlideView" slide-view summary of all frames "TransparentColor" color to be interpreted as transparent - Importing the "ColorMap" element from an animated GIF will return the color maps of all frames as a list.
- GIF supports color palettes of at most 256 colors, always storing colors at a resolution of 8 bits per color channel.
- "DisposalOperation" specifies how to dispose the current frame before creating the next frame. Possible values are:
-
"None" no disposal "Background" replace with a background color "Previous" replace with the previous frame Missing["NotAvailable"] missing disposal operation
Options


- Import and Export options:
-
ImageSize Automatic overall image size "ImageTopOrientation" Top orientation of the image as stored in the file - Images are by default exported at full size.
- Export options:
-
"ColorMapLength" Automatic number of colors to use for quantization Dithering "FloydSteinberg" dithering algorithm used for generating the color-reduction table ImageFormattingWidth $ImageFormattingWidth target width when formatting an object "QuantizationMethod" Automatic a method to use for quantization "TransparentColor" Automatic color to be interpreted as transparent - Possible settings for Dithering are "FloydSteinberg" or None.
- Export options for animated GIFs:
-
"ControlAppearance" "Generic" how Manipulate control elements are rendered in the exported file "DisplayDurations" Automatic display duration for each frame in seconds "Interlaced" False whether to store graphics in interlaced form to allow progressive rendering AnimationRepetitions 1 how many times the animation plays before stopping "DisposalOperation" Automatic disposal operation before creating the next frame - The following settings can be given for "ControlAppearance":
-
Automatic captures user controls exactly as seen in the notebook interface, using the style elements of the local computer system "Generic" renders graphical controls in a generic style None excludes control elements when exporting an animation - "DisplayDurations"->{d1,d2,…} specifies the display durations for each frame in an animated GIF.
- Possible values for "DisposalOperation" are:
-
Automatic or None no disposal "Background" replace with a background color "Previous" replace with the previous frame
Examples
open allclose allBasic Examples (4)
Scope (2)
This rasterizes an arbitrary expression and converts the result to a GIF file:
Create an animated GIF by exporting a list of Graphics expressions:
Import Elements (26)
Available Elements (3)
Data Representation (11)
Metadata (12)
"AnimationRepetitions" (1)
"ColorSpace" (1)
Get the color encoding used on export:
Use ImageColorSpace to get the color space of an imported image:
"ImageSize" (1)
Get the dimensions of the images stored in the file:
Using ImageDimensions on an imported image gives the same result:
Import Options (2)
Export Options (12)
"ControlAppearance" (1)
Specify whether the control menus in Manipulate should be exported as well:
ImageSize (1)
"QuantizationMethod" (1)
"TransparentColor" (1)
Specify the color to be interpreted as transparent:
The transparent color is replaced with Transparent:
"DisposalOperation" (3)
Export an animated GIF with a transparent background and default "DisposalOperation":
Each frame is drawn on top of the previous one:
To get frames drawn always on the clear canvas (filled with a background color), use "DisposalOperation"->"Background":
Specify disposal operations for each frame separately:
Specify None as a disposal operation for the first frame to see the difference between the "Previous" and "Background" operations: