GIF (.gif)

Background

    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 8bit color palette.
    Supports transparency.
    Developed in 1987 by CompuServe.

Import and 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.

Notebook Interface

  • 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

  • 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:
  • ImageSizeAutomaticoverall image size
    "ImageTopOrientation"Toporientation of the image as stored in the file
  • Images are by default exported at full size.
  • Export options:
  • Dithering"FloydSteinberg"dithering algorithm used for generating the color-reduction table
    ImageFormattingWidth$ImageFormattingWidthtarget width when formatting an object
    "TransparentColor"Automaticcolor 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"Automaticdisplay duration for each frame in seconds
    "Interlaced"Falsewhether to store graphics in interlaced form to allow progressive rendering
    AnimationRepetitions1how many times the animation plays before stopping
  • The following settings can be given for "ControlAppearance":
  • Automaticcaptures 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
    Noneexcludes control elements when exporting an animation
  • "DisplayDurations"->{d1,d2,} specifies the display durations for each frame in an animated GIF.

Examples

open allclose all

Basic Examples  (4)

Import a GIF file:

In[1]:=
Click for copyable input
Out[1]=

Summary of the image:

In[1]:=
Click for copyable input
Out[1]=

Read an animated GIF as a list of images:

In[1]:=
Click for copyable input
Out[1]=

Import this file as an animation:

In[2]:=
Click for copyable input
Out[2]=

Export an image object to GIF:

In[1]:=
Click for copyable input
Out[1]=

Scope  (2)

Import Elements  (26)

Import Options  (2)

Export Options  (7)

Possible Issues  (1)

See Also

"JPEG"  "PNG"  "TIFF"

Tutorials

Introduced in 1999
(4.0)
| Updated in 2017
(11.2)