PNG (.png)

  • Import and Export fully support Version 1.2 of the PNG format.

BackgroundBackground

    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 a single image.
    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 up to 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 and ExportImport and Export

  • Import["file.png"] imports a PNG file as an image.
  • Export["file.png",expr] exports an image, graphics, or any other expression as a raster image to PNG.
  • 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.
  • Import["file.png",elem] imports the specified element from a PNG file.
  • Import["file.png",{elem,suba,subb,}] imports a subelement.
  • Import["file.png",{{elem1,elem2,}}] imports multiple elements.
  • The import format can be specified with Import["file","PNG"] or Import["file",{"PNG",elem,}].
  • Export["file.png",expr,elem] creates a PNG file by treating expr as specifying element elem.
  • Export["file.png",{expr1,expr2,},{{elem1,elem2,}}] treats each as specifying the corresponding .
  • Export["file.png",expr,opt1->val1,] exports expr with the specified option elements taken to have the specified values.
  • Export["file.png",{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 PNG 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:
  • "Data"array of color values
    "Graphics"Graphics object representing an image
    "Image"raster image, given as an Image object
    "GrayLevels"array of normalized gray-level values
    "RGBColorArray"array of RGBColor objects
  • Import and Export by default use the element for PNG files.
  • Elements of PNG files using a color-reduction palette:
  • "ColorMap"color-reduction palette used in the file
    "RawData"array of color indices
  • Advanced Import elements:
  • "BitDepth"bits used to represent each color channel in the file
    "ColorProfileData"embedded color profile, given as a ColorProfileData object
    "ColorSpace"color encoding used in the file
    "Comments"textual information
    "ImageSize"raster dimensions

OptionsOptions

  • General option:
  • ImageSizeAutomaticoverall image size
  • Import options:
  • "TakeRows"{1,-1}rows to import
  • Export option:
  • "ImageTopOrientation"Toporientation of the exported image
    "Comments"Nonetextual information

ExamplesExamplesopen allclose all

Basic Examples  (3)Basic Examples  (3)

Import a PNG file as an image:

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

Show the elements that can be imported from this file:

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

Get the and elements:

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

Export arbitrary inline graphics to PNG:

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

Export a Wolfram Language expression as a raster to PNG:

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=
Introduced in 2003
(5.0)
| Updated in 2014
(10.0)