Routines (alphabetical) > Routines: W > WRITE_PPM

# WRITE_PPM

The WRITE_PPM procedure writes an image to a PPM (TrueColor) or PGM (gray scale) file. This routine is written in the IDL language. Its source code can be found in the file `write_ppm.pro` in the `lib` subdirectory of the IDL distribution.

Note: WRITE_PPM only writes 8-bit deep PGM/PPM files of the standard type. Images should be ordered so that the first row is the top row.
PPM/PGM format is supported by the PBMPLUS toolkit for converting various image formats to and from portable formats, and by the Netpbm package.

## Example

The following lines create an image in an IDL graphics window, read it from the window and write it as a `.ppm` file in the temporary directory, then read the `.ppm` file and display it in the same graphics window:

; Save device settings and tell IDL to use a color table
DEVICE, GET_DECOMPOSED=old_decomposed
DEVICE, DECOMPOSED=0
LOADCT, 14
; Create an image and display it
IMAGE1 = DIST(300)
WINDOW, 1, XSIZE=300, YSIZE=300
TV, IMAGE1
; Write a PNG file to the temporary directory
; Note the use of the TRUE keyword to TVRD
filename = FILEPATH('test.ppm', /TMP)
WRITE_PPM, filename, TVRD(/TRUE)
PRINT, 'File written to ', filename
; Read in the file
IMAGE2 = READ_PPM(filename)
; Display the IMAGE1 and IMAGE2 side by side
; Note the use of the TRUE keyword to TV
WINDOW, 1, XSIZE=600, YSIZE=300, $
TITLE='Original (left) and Image read from file (right)'
TV, IMAGE1, 0
TV, IMAGE2, 1, /TRUE
; Restore device settings.
DEVICE, DECOMPOSED=old_decomposed

## Syntax

WRITE_PPM, Filename, Image [, /ASCII]

## Arguments

### Filename

A scalar string specifying the full pathname of the PPM or PGM file to write.

### Image

The 2D (gray scale) or 3D (TrueColor) array to be written to a file.

## Keywords

### ASCII

Set this keyword to force WRITE_PPM to use formatted ASCII input/output to write the image data. The default is to use the far more efficient binary input/output (RAWBITS) format.

## Version History

4.0 | Introduced

## See Also

READ_PPM, QUERY_* Routines