ExportToGIF
Summary
Exports the page layout or data frame of a map document (.mxd) to the Graphic Interchange (GIF) format.
Discussion
GIF files are a standard raster format for use on the Web. GIFs cannot contain more than 256 colors (8 bits per pixel), which along with optional lossless RLE or LZW compression makes them smaller than other file formats. They are a good choice for maps that contain a limited number of colors, but may not display continuous raster data correctly due to the color limitation. GIF files also have the ability to define a transparent color; part of the image can display as transparent in a Web browser, allowing backgrounds, images, or colors to show through. GIFs exported from the data view in ArcMap can be generated with an accompanying world file for use as georeferenced raster data.
To export a single data frame instead of the entire page layout, pass a DataFrame object to the function's data_frame parameter. Because data frame exports do not have an associated page to provide height and width information, you must provide this via the df_export_width and df_export_height parameters.
Controlling graphic quality of the generated image differs for page layout exports versus data frame exports. When exporting a page layout, control image detail by changing the resolution parameter. When exporting a data frame, keep the resolution parameter at its default value, and change the df_export_width and df_export_height parameters to alter image detail. The height and width parameters directly control the number of pixels generated in the export file and are only used when exporting a data frame. Images with larger numbers of pixels will have higher image detail. For most page layout exports, the default parameter values should generate good results and nice looking export images on the first try. For data frame exports, you may need to experiment with the df_export_width and df_export_height values a few times before getting the result you want.
World files are not generated for page layouts; a referenced data frame must be provided or the export will fail.
Refer to the Exporting your map topic in ArcGIS Help for more detailed discussions on exporting maps.
Syntax
Parameter | Explanation | Data Type |
map_document |
A variable that references a MapDocument object. | MapDocument |
out_gif |
A string that represents the path and file name for the output export file. | String |
data_frame |
A variable that references a DataFrame object. Use the string/constant "PAGE_LAYOUT" to export the map document's page layout instead of an individual data frame. (The default value is PAGE_LAYOUT) | Object |
df_export_width |
A number that defines the width of the export image in pixels for a data frame export. df_export_width is only used when exporting a data frame. Exporting a page layout uses the map document page width instead of df_export_width. (The default value is 640) | Integer |
df_export_height |
A number that defines the height of the export image in pixels for a data frame export. df_export_height is only used when exporting a data frame. Exporting a page layout uses the map document page height instead of df_export_height. (The default value is 480) | Integer |
resolution |
A number that defines the resolution of the export file in dots per inch (DPI). (The default value is 96) | Integer |
world_file |
If set to True, a georeferenced world file is created. The file contains pixel scale information and real-world coordinate information. (The default value is False) | Boolean |
color_mode |
This value specifies the number of bits used to describe color.
(The default value is 8-BIT_PALETTE) | String |
gif_compression |
This value represents a compression scheme.
(The default value is NONE) | String |
background_color |
A defined color is used as a background to the image, or as a mask in the case of monochrome masked exports. (The default value is 255, 255, 255) | String |
transparent_color |
A defined color to be displayed as transparent in the image. | String |
interlaced |
If set to True, an interlaced image will be created. An interlaced image displays as a series of scan lines rather than as a whole image at one time. (The default value is False) | Boolean |
Code Sample
This script opens a map document and exports the page layout to a GIF file using default values for all options.
import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd") arcpy.mapping.ExportToGIF(mxd, r"C:\Project\Output\Project.gif") del mxd
This script will export a single data frame instead of the entire page layout, similar to exporting from data view in the ArcMap application. The default values for df_export_width and df_export_height are 640 and 480. By passing larger values for these parameters, we are able to produce an output image with higher detail. Setting world_file = True generates a georeferenced world file in the same directory as the output file.
import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Transportation")[0] arcpy.mapping.ExportToGIF(mxd, r"C:\Project\Output\ProjectDataFrame.gif", df, df_export_width=1600, df_export_height=1200, world_file=True) del mxd