PNM (.pnm)


    MIME types: image/x-portable-anymap, image/pbm
    PNM raster image format.
    Generic format of the Portable family of image formats.
    Includes the PBM (monochrome), PGM (gray-level), and PPM (RGB color) image formats.
    Native format of the Netpbm graphics software package.
    Primarily used as an intermediate file format on Unix systems.
    PNM is an acronym derived from Portable Any Map.
    ASCII or binary format.
    Stores raster images formatted as plain text, representing each pixel as a color value.

Import and ExportImport and Export

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

Notebook InterfaceNotebook Interface

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


  • 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
  • Import by default uses "Image" for single-frame PNM files and "ImageList" for multi-frame PNM files.
  • Advanced Import elements:
  • "BitDepth"bits used to represent each color channel in the file
    "Channels"the number of color channels used in the file
    "ColorSpace"color space of the image
    "DataType"data type used for storing pixel elements
    "ImageSize"raster dimensions
    "Summary"summary of the file


ExamplesExamplesopen allclose all

Basic Examples  (3)Basic Examples  (3)

Import a PNM file:

Click for copyable input

Summary of an image:

Click for copyable input

Export an image object to PNM:

Click for copyable input
Introduced in 1999
| Updated in 2016