|
SOLUTIONS
|
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.
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 ExportImport and Export
- Import["file.gif"] imports a GIF file, returning a single Image object or a list of images.
- Export["file.gif", expr] exports graphics, images, or any other expression to GIF.
- Export["file.gif", {g1, g2, ...}] exports a list of graphics or images as an animation.
- When exporting Mathematica 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.
- Import["file.gif", elem] imports the specified element from a GIF file.
- Import["file.gif", {elem, sub, ...}] 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
as specifying the corresponding
. - 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.
- ImportString and ExportString support the GIF format.
ElementsElements
- 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 "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 - Import by default uses the
element for a static GIF, and
for an animated GIF. - Import of an animated GIF with element
gives the first frame of the animation. - Export by default generates an animated GIF if the expression supplied is a list of images, and a static GIF otherwise.
- Export with element
or
always generates a static GIF. - Advanced data representation elements:
-
"Data" array of RGB color values "GrayLevels" array of normalized gray-level values "RGBColorArray" array of RGBColor objects - For animated GIFs, the above data representation elements are taken to be lists of the respective expressions.
- 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 "ColorMap" color reduction palette, given as a list of color values "GlobalColorMap" color palette used by default for individual animation frames "DisplayDurations" display durations of animation frames, given in seconds "ImageCount" number of frames in an animated GIF "ImageSize" overall image size "RawData" array of color map indices "Comments" user comments stored in the file - Importing the
element from an animated GIF will return the color maps of all frames as a list.
OptionsOptions
- General options:
-
Background Automatic background color shown in transparent image regions ImageSize Automatic overall image size - Images are by default exported at full size.
- Import and Export option:
-
"ImageTopOrientation" Top orientation of the image as stored in the file - Export options:
-
"DitheringMethod" "FloydSteinberg" dithering algorithm used for generating the color-reduction table "TransparentColor" Automatic color 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
are
or None. - Detailed properties and settings for an animated GIF:
-
"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 - GIF supports color palettes of at most 256 colors, always storing colors at a resolution of 8 bits per color channel.
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.
- The following settings can be given for AnimationRepetitions:
-
n positive integer, specifying how many times the animation should be played Infinity animation is repeated indefinitely
ExamplesExamplesopen allclose all
Basic Examples (5)Basic Examples (5)
Import a raster image from a GIF file:
| In[1]:= |
| Out[1]= | ![]() |
Export an image object to GIF:
| In[1]:= |
| Out[1]= |
Read an animated GIF as a list of images:
| In[1]:= |
| Out[1]= | ![]() |
Import this file as an animation:
| In[2]:= |
| Out[2]= | ![]() |
This rasterizes an arbitrary expression and converts the result to a GIF file:
| In[1]:= |
| Out[1]= |
| In[2]:= |
| Out[2]= |
Create an animated GIF by exporting a list of Graphics expressions:
| In[1]:= |
| Out[1]= |
Import the resulting file as an animation:
| In[2]:= |
| Out[2]= | ![]() |
| In[1]:= |
| Out[1]= | ![]() |
New in 4 | Last modified in 7
Mathematica 9 is now available!
New to Mathematica?
Find your learning path »
Have a question?
Ask support »








