page_title: Netpbm
section_title: PPM example
hierarchical_section_title: Netpbm / File formats / Description / PPM example
caption_attribution_description: English: Example of PPM format
context_page_description: Netpbm is an open-source package of graphics programs and a programming library. It is used mainly in the Unix world, where one can find it included in all major open-source operating system distributions, but also works on Microsoft Windows, macOS, and other operating systems.
context_section_description: This is an example of a color RGB image stored in PPM format. There is a newline character at the end of each line.
  P3
  3 2
  255
  # The part above is the header
  # "P3" means this is a RGB color image in ASCII
  # "3 2" is the width and height of the image in pixels
  # "255" is the maximum value for each color
  # The part below is image data: RGB triplets
  255   0   0  # red
    0 255   0  # green
    0   0 255  # blue
  255 255   0  # yellow
  255 255 255  # white
    0   0   0  # black
  The P6 binary format of the same image represents each color component of each pixel with one byte (thus three bytes per pixel) in the order red, green, then blue. The file is smaller, but the color information is difficult to read by humans. The header remains in ASCII and the arguments are still separated by a whitespace. The binary image information comes after the header (which ends with a whitespace).
  The PPM format is not compressed, and thus requires more space and bandwidth than a compressed format would. For example, the above 192×128 PNG (Portable Network Graphics) image has a file size of 166 bytes. When converted to a 192×128 PPM image, the file size is 73,848 bytes. The PPM format is generally an intermediate format used for image work before converting to a more efficient format, for example the PNG format, without any loss of information in the intermediate step.
  
  The image shown above using only 0 or the maximal value for the red-green-blue channels can be also encoded as:
  P3
  # The same image with width 3 and height 2,
  # using 0 or 1 per color (red, green, blue)
  3 2 1
  1 0 0   0 1 0   0 0 1
  1 1 0   1 1 1   0 0 0
  
  White space including line ends and comment lines is syntactically equivalent to a single space within the PNM headers. For the plain formats P1...P3 this also affects the pixmap lines; in fact lines should be limited to 70 characters:
  P3 3 2 1  1 0 0   0 1 0   0 0 1  1 1 0   1 1 1   0 0 0
caption: Image (magnified)
exif: {}