PNG (.png)

Background & Context

    • Registered MIME type: image/png
    • PNG raster image format.
    • Commonly used for graphics and photographic images on the web.
    • PNG is an acronym for Portable Network Graphics.
    • Binary format.
    • Stores both static and animated images.
    • Stores color bitmaps at a resolution of 8 or 16 bits per channel.
    • Grayscale images are represented at a depth of 1, 2, 4, 8, or 16 bits per pixel.
    • Supports alpha channels for 8-bit and 16-bit RGB and grayscale images.
    • Has support for color-reduction palettes using 2, 4, 16 or 256 8-bit RGB colors.
    • Developed in 1995 as an open and patent-free alternative to the GIF format.
    • Published as international standard ISO/IEC 15948:2003 and ISO/IEC 15948:2004.

Import & Export

  • Import["file.png"] imports a PNG file, returning a single Image object or a list of images.
  • Import["file.png",elem] imports the specified element from a PNG file.
  • The import format can be specified with Import["file","PNG"] or Import["file",{"PNG",elem,}].
  • Export["file.png",expr] exports an image, graphics, or any other expression as an image to a PNG file.
  • Export["file.png",{expr1,expr2,}] exports a list of graphics or images as an animation.
  • Export["file.png",Manipulate[]] exports an animated demonstration of a Manipulate object.
  • When exporting Wolfram Language graphics or arbitrary expressions to PNG, the resulting image has the same raster size as its displayed form.
  • Image objects are by default exported at their raster size.
  • Because PNG 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 PNG format.

Notebook Interface

  • In the notebook front end, Insert Picture and the Open menu allow the import of a PNG file into a cell.
  • Save Selection As exports the selected part of a notebook as a PNG file.

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:
  • "AnimatedImage"animated PNG represented as an AnimatedImage object
    "Animation"animated PNG represented as an animation object
    "Data"array of pixel values
    "Graphics"first frame of a PNG file, given as a Graphics object
    "GraphicsList"frames of an animated PNG as a list of Graphics objects
    "Image"first frame of a PNG file, given as an Image object
    "ImageList"frames of an animated PNG as a list of Image objects
    "RawData"array of color map indices
    {"Thumbnail",size}thumbnail of a given size (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 PNG and "ImageList" for an animated PNG.
  • Import of an animated PNG with element "Image" gives the first frame of the animation.
  • Export by default generates an animated PNG if the expression supplied is a list of images or a Manipulate, and a static PNG otherwise.
  • Advanced Import elements:
  • "AnimationRepetitions"how many times the animation is played before stopping
    "BitDepth"bits used to represent each color channel in the file
    "BlendOperation"whether to perform alpha blending to create the next frame
    "CameraTopOrientation"orientation of the camera when the picture was taken
    "Channels"the number of color channels used in the file
    "ColorMap"color reduction palette, given as a list of color values
    "ColorProfileData"embedded color profile, given as a ColorProfileData object
    "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
  • whether the flash was fired
  • "GeoPosition"latitude and longitude represented as a GeoPosition object
  • image creation date and time registered by GPS
  • "ImageCount"number of frames in an animated PNG
    "ImageSize"overall image size
    "RedEyeCorrection"whether a red-eye correction was performed
    "Summary"summary of the file
    "SummarySlideView"slide-view summary of all frames
  • PNG supports a color palette 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 fully transparent black background
    "Previous"replace with the previous frame
  • "BlendOperation" specifies whether to alpha blend the next frame to the current frame, after disposal.
  • Metadata elements:
  • "Exif"formatted Exif (Exchange image file format)
    "IPTC"formatted IPTC (International Press Telecommunications Council)
    "XMP"formatted XMP (Extensible metadata platform)
    "MetaInformation"combination of all formatted metadata present in the file
  • Raw metadata, as stored in the file, can be imported using "RawExif", "RawXMP" and "RawIPTC" elements which are returned in an association.
  • All Exif and IPTC tags can be imported individually. Common tags include:
  • "ApertureValue"lens aperture
    "Artist"photographer or image creator
    "DateTime"image creation date and time
    "ExposureTime"exposure time, given in seconds
  • flash information: flash fired, red-eye correction, etc.
  • "FNumber"F number
    "FocalLength"actual focal length of the lens, given in millimeters
    "GPSAltitude"altitude of the GPS position
    "GPSLatitude"latitude of the GPS position
    "GPSLongitude"longitude of the GPS position
    "Make"manufacturer of the recording equipment
    "Model"model name or model number of the equipment
    "Software"name and version of the software or firmware of the camera or image input device used to generate the image


  • Import and Export options:
  • ImageSizeAutomaticoverall image size
    IncludeMetaInformationAllmetadata types to import and export
    "ImageTopOrientation"Automaticorientation of the image as stored in the file
  • Import option:
  • "TakeRows"{1,-1}rows to import
  • Export options:
  • ColorSpaceAutomaticcolor encoding to be used in the file
    "ColorMapLength"Automaticnumber of colors to use for quantization
    "Comments"Nonetextual information
    CompressionLevelAutomaticcompression level, given as a number between 0 and 1
    Dithering"FloydSteinberg"dithering algorithm used for generating the color-reduction table
    "QuantizationMethod"Automaticquantization method used by ColorQuantize
  • Use DitheringNone to perform no dithering.
  • Supported ColorSpace settings are: "Grayscale" and "RGB". Using ColorSpace->Automatic, Export attempts to create a PNG file with the same color space.
  • Export options for animated PNGs:
  • AnimationRepetitions1how many times the animation plays before stopping
    "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
  • 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 PNG.


open allclose all

Basic Examples  (4)

Import a PNG file as an image:

Summary of an image:

Import an animated PNG as an animation:

Export an RGB image to PNG:

Scope  (3)

Export a Wolfram Language expression to PNG:

Export a list of expressions to an animated PNG:

Import as an animation:

Export a Manipulate as an animated PNG:

Use Rasterize to export a screenshot of the Manipulate into a PNG file:

Import Elements  (41)

Available Elements  (5)

List of available elements:

List of available Exif elements:

List of available IPTC elements:

Get image-related information as a list of rules:

Import some image options:

The "Options" element does not return all options that are present in the imported image:

Data Representation  (11)

"AnimatedImage"  (1)

Import a multiframe PNG file as an AnimatedImage:

"Animation"  (1)

"ColorMap"  (1)

Generate a PNG image with a color-reduction palette:

Get the color-reduction palette from a generated image:

Visualize the color-reduction palette:

Apply the color map to the raw data to create the stored image:

"Data"  (1)

Get the image data:

Use the image data to create the image:

"Graphics"  (1)

Import as a Graphics object:

"GraphicsList"  (1)

Get the list of graphics objects:

"Image"  (1)

Import as an Image object:

The default element is also "Image":

"ImageList"  (1)

Get the data as a list of Image objects:

"RawData"  (1)

Get the raw data from the first frame of the animated PNG:

Plot the array of raw data:

Use the color map to create the stored image:

"Thumbnail"  (1)

Import a thumbnail of the image:

Specify the thumbnail size:

ThumbnailList"  (1)

Import a list of thumbnails from an animated PNG file:

Metadata  (25)

"BitDepth"  (1)

Get the bit count for the representation of each color channel:

"BlendOperation"  (1)

Get the blend operation:

"CameraTopOrientation"  (1)

Get the camera orientation at the capture time:

"Channels"  (1)

Get the number of image channels used:

"ColorProfileData"  (1)

Get the embedded color profile, given as a ColorProfileData object:

The color profile is stored in the ColorSpace option of the imported image:

"ColorSpace"  (1)

Get the color encoding used on export:

Use ImageColorSpace to get the color space of an imported image:

"DateTime"  (1)

Get the date and time that the image was captured:

"DisposalOperation"  (1)

Get the disposal operation:

"Exif"  (3)

Import Exif metadata:

Extract an individual tag from the association:

Individual Exif tags can also be imported directly:

Some Exif tags are processed to give more detailed information:

Compare with the raw "FlashInfo" tag:

"FlashUsed"  (1)

Import a tag that shows whether the flash fired:

"FlashUsed" is a subelement of the "FlashInfo" element:

Extract "FlashUsed" from the full "Exif":

"GeoPosition"  (2)

Get the image geo position:

The image geo position may be unavailable:

"GPSDateTime"  (1)

Get the image creation date and time registered by GPS:

"ImageCount"  (1)

Get the number of frames stored in an animated PNG file:

"ImageSize"  (1)

Get the dimensions of the image stored in the file:

Using ImageDimensions on an imported image gives the same result:

"IPTC"  (1)

Get IPTC metadata:

Get the Application2 schema of the IPTC metadata:

"MetaInformation"  (1)

Get all the metadata:

"RawExif"  (1)

Import unprocessed Exif metadata using the "RawExif" element:

"RawExif" returns the raw values stored in the file:

Compare with the interpreted focal length:

"RawIPTC"  (1)

Import unprocessed IPTC metadata:

"RawXMP"  (1)

Import unprocessed XMP metadata:

"Summary"  (1)

Get the image summary:

"SummarySlideView"  (1)

Get the image frames' summary:

"XMP"  (1)

Get XMP metadata:

Import Options  (6)

ImageResolution  (1)

By default, the image resolution is extracted from the file:

Specify the resolution of the imported image:

Specify different resolutions in the and directions:

ImageSize  (1)

By default, images are imported in their full resolution:

Specify the raster size of the imported PNG image:

IncludeMetaInformation  (3)

Import the image with no metadata:

Import the image with "XMP" metadata only:

"TakeRows"  (1)

By default, all rows are imported:

Import only the specified rows:

Export Options  (10)

AnimationRepetitions  (1)

Specify how many times the animation plays before stopping:

"ColorMapLength"  (1)

Decrease the file size by specifying a smaller length of a color map:

"ControlAppearance"  (1)

Specify whether the control menus in Manipulate should be exported as well:

Export no controls:

Export with graphical controls:

CompressionLevel  (1)

Use higher compression levels to decrease a file size:

Higher compression levels require more time to generate a PNG file:

"DisplayDurations"  (1)

Specify display duration (in seconds) for each frame of animation:

Dithering  (1)

Show the effect of dithering:

Show the areas with significant difference:

ImageSize  (1)

By default, the image is exported in the full resolution:

Specify the raster size of exported image:

"ImageTopOrientation"  (1)

By default, the upright image is exported using "ImageTopOrientation"->Top:

Specify the orientation:

Import using the original orientation:

IncludeMetaInformation  (1)

By default, all existing meta-information is exported:

Specify classes of metadata to export:

"QuantizationMethod"  (1)

Show the effects of various quantization methods:

Show the areas with significant difference: