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 following reference pages for full general information:
-
Import, Export import from or export to a file CloudImport, CloudExport import from or export to a cloud object ImportString, ExportString import from or export to a string ImportByteArray, ExportByteArray import from or export to a byte array
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 "Summary" summary of the file "Rules" list of rules for all available elements - 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 {"ThumbnailList",frames} a list of thumbnails (default frames=All) - 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 "FlashUsed" - whether the flash was fired
"GeoPosition" latitude and longitude represented as a GeoPosition object "GPSDateTime" - image creation date and time registered by GPS
"ImageCount" number of frames in an animated PNG "RasterSize" raster dimensions "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 "FlashInfo" - 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
Options


- Import and Export options:
-
IncludeMetaInformation All metadata types to import and export "ImageTopOrientation" Automatic orientation of the image as stored in the file RasterSize Automatic dimensions of the image - Import option:
-
"TakeRows" {1,-1} rows to import - Export options:
-
ColorSpace Automatic color encoding to be used in the file "ColorMapLength" Automatic number of colors to use for quantization "Comments" None textual information CompressionLevel Automatic compression level, given as a number between 0 and 1 Dithering "FloydSteinberg" dithering algorithm used for generating the color-reduction table "QuantizationMethod" Automatic quantization 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:
-
AnimationRepetitions Infinity how many times the animation plays before stopping "ControlAppearance" Automatic how Manipulate control elements are rendered in the exported file "DisplayDurations" Automatic display duration for each frame in seconds "Interlaced" False whether to store graphics in interlaced form to allow progressive rendering "RemoveDuplicatedFrames" False whether to remove duplicated frames - The following settings can be given for "ControlAppearance":
-
Automatic captures 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 None excludes control elements when exporting an animation - "DisplayDurations"->{d1,d2,…} specifies the display durations for each frame in an animated PNG.
Examples
open allclose allBasic Examples (4)Summary of the most common use cases
Import a PNG file as an image:

https://wolfram.com/xid/0fgx2yf-vga


https://wolfram.com/xid/0fgx2yf-1bhlt8

Import an animated PNG as an animation:

https://wolfram.com/xid/0fgx2yf-vlxggx


https://wolfram.com/xid/0fgx2yf-rt5o0j

Scope (3)Survey of the scope of standard use cases
Export a Wolfram Language expression to PNG:

https://wolfram.com/xid/0fgx2yf-rxkucu

https://wolfram.com/xid/0fgx2yf-egdpw1

Export a list of expressions to an animated PNG:

https://wolfram.com/xid/0fgx2yf-hvrc0j

https://wolfram.com/xid/0fgx2yf-bwyy6u


https://wolfram.com/xid/0fgx2yf-59wwi7

Export a Manipulate as an animated PNG:

https://wolfram.com/xid/0fgx2yf-ewtdwv


https://wolfram.com/xid/0fgx2yf-psam3y

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

https://wolfram.com/xid/0fgx2yf-wf5tov

Import Elements (40)
Available Elements (4)

https://wolfram.com/xid/0fgx2yf-1g2ndh

List of available Exif elements:

https://wolfram.com/xid/0fgx2yf-e619fh

List of available IPTC elements:

https://wolfram.com/xid/0fgx2yf-txorq8

Get image-related information as a list of rules:

https://wolfram.com/xid/0fgx2yf-myzd73

Data Representation (11)
"AnimatedImage" (1)
Import a multiframe PNG file as an AnimatedImage:

https://wolfram.com/xid/0fgx2yf-wzep9m

"ColorMap" (1)
Generate a PNG image with a color-reduction palette:

https://wolfram.com/xid/0fgx2yf-dioy7i

Get the color-reduction palette from a generated image:

https://wolfram.com/xid/0fgx2yf-cy3ssw

Visualize the color-reduction palette:

https://wolfram.com/xid/0fgx2yf-0vipsx

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

https://wolfram.com/xid/0fgx2yf-fdn6ld

https://wolfram.com/xid/0fgx2yf-qo9gx8

"Data" (1)
"Graphics" (1)
Import as a Graphics object:

https://wolfram.com/xid/0fgx2yf-oxk5kn


https://wolfram.com/xid/0fgx2yf-oxk2tw

"GraphicsList" (1)
"Image" (1)
Import as an Image object:

https://wolfram.com/xid/0fgx2yf-dlnomo


https://wolfram.com/xid/0fgx2yf-dwk74o

The default element is also "Image":

https://wolfram.com/xid/0fgx2yf-534az9

"ImageList" (1)
"RawData" (1)
Get the raw data from the first frame of the animated PNG:

https://wolfram.com/xid/0fgx2yf-pcy53


https://wolfram.com/xid/0fgx2yf-suc30t

Use the color map to create the stored image:

https://wolfram.com/xid/0fgx2yf-jpzddq

https://wolfram.com/xid/0fgx2yf-cm4eco

"Thumbnail" (1)
Metadata (25)
"BitDepth" (1)
"BlendOperation" (1)
"CameraTopOrientation" (1)
"Channels" (1)
"ColorProfileData" (1)
Get the embedded color profile, given as a ColorProfileData object:

https://wolfram.com/xid/0fgx2yf-1xdwml

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

https://wolfram.com/xid/0fgx2yf-mpv214

"ColorSpace" (1)
Get the color encoding used on export:

https://wolfram.com/xid/0fgx2yf-wb968h

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

https://wolfram.com/xid/0fgx2yf-ca8qqr

"DateTime" (1)
"DisposalOperation" (1)
"Exif" (3)

https://wolfram.com/xid/0fgx2yf-49xowb

Extract an individual tag from the association:

https://wolfram.com/xid/0fgx2yf-omm9zg

Individual Exif tags can also be imported directly:

https://wolfram.com/xid/0fgx2yf-55ozsh

Some Exif tags are processed to give more detailed information:

https://wolfram.com/xid/0fgx2yf-xpmhcz

Compare with the raw "FlashInfo" tag:

https://wolfram.com/xid/0fgx2yf-3h2d51

"FlashUsed" (1)
Import a tag that shows whether the flash fired:

https://wolfram.com/xid/0fgx2yf-xabiy

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

https://wolfram.com/xid/0fgx2yf-v4pueu

Extract "FlashUsed" from the full "Exif":

https://wolfram.com/xid/0fgx2yf-h0cksj

"GeoPosition" (2)
"GPSDateTime" (1)
"ImageCount" (1)
"IPTC" (1)
"MetaInformation" (1)
"RasterSize" (1)
Get the dimensions of the image stored in the file:

https://wolfram.com/xid/0fgx2yf-ma62cc

Using ImageDimensions on an imported image gives the same result:

https://wolfram.com/xid/0fgx2yf-hjusgl

"RawExif" (1)
Import unprocessed Exif metadata using the "RawExif" element:

https://wolfram.com/xid/0fgx2yf-mf9zrs

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

https://wolfram.com/xid/0fgx2yf-dj1jcj

Compare with the interpreted focal length:

https://wolfram.com/xid/0fgx2yf-k1llg3

"RawIPTC" (1)
"RawXMP" (1)
"SummarySlideView" (1)
Import Options (6)
ImageResolution (1)
By default, the image resolution is extracted from the file:

https://wolfram.com/xid/0fgx2yf-kux3uu

Specify the resolution of the imported image:

https://wolfram.com/xid/0fgx2yf-f98eh7

Specify different resolutions in the and
directions:

https://wolfram.com/xid/0fgx2yf-rc4e7v

IncludeMetaInformation (3)
RasterSize (1)
Export Options (11)
AnimationRepetitions (1)
"ColorMapLength" (1)
"ControlAppearance" (1)
Specify whether the control menus in Manipulate should be exported as well:

https://wolfram.com/xid/0fgx2yf-pxxhc


https://wolfram.com/xid/0fgx2yf-wqu779

Export with graphical controls:

https://wolfram.com/xid/0fgx2yf-oltgq0

CompressionLevel (1)
Use higher compression levels to decrease a file size:

https://wolfram.com/xid/0fgx2yf-v1ol6p

https://wolfram.com/xid/0fgx2yf-9q9vfo


https://wolfram.com/xid/0fgx2yf-x514hb

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

https://wolfram.com/xid/0fgx2yf-epoouq

"DisplayDurations" (1)
Dithering (1)
"ImageTopOrientation" (1)
By default, the upright image is exported using "ImageTopOrientation"->Top:

https://wolfram.com/xid/0fgx2yf-kje3az

https://wolfram.com/xid/0fgx2yf-9ogv7d


https://wolfram.com/xid/0fgx2yf-oj40fq


https://wolfram.com/xid/0fgx2yf-i70bei


https://wolfram.com/xid/0fgx2yf-olrxst

Import using the original orientation:

https://wolfram.com/xid/0fgx2yf-s4jg2y

IncludeMetaInformation (1)
By default, all existing meta-information is exported:

https://wolfram.com/xid/0fgx2yf-18ggu3


https://wolfram.com/xid/0fgx2yf-oweiqp

Specify classes of metadata to export:

https://wolfram.com/xid/0fgx2yf-461z90


https://wolfram.com/xid/0fgx2yf-lvdb2h

"QuantizationMethod" (1)
RasterSize (1)
By default, the image is exported in the full resolution:

https://wolfram.com/xid/0fgx2yf-lszysm

https://wolfram.com/xid/0fgx2yf-bhjnpf


https://wolfram.com/xid/0fgx2yf-t9ntr8


https://wolfram.com/xid/0fgx2yf-7p8hv4

Specify the raster size of the exported image:

https://wolfram.com/xid/0fgx2yf-3ie1wu


https://wolfram.com/xid/0fgx2yf-ss5jdi

"RemoveDuplicatedFrames" (1)
Create a video with duplicated frames:

https://wolfram.com/xid/0fgx2yf-w9tof5


https://wolfram.com/xid/0fgx2yf-bfg1ow

Export all duplicated frames to an animated PNG:

https://wolfram.com/xid/0fgx2yf-bmlhhu

Export while removing duplicated frames and notice the file size reduction:

https://wolfram.com/xid/0fgx2yf-eg16n1
