The PGM (or Portable Gray Map) image format is encoded in human-readable text. Below is a brief synopsis of the format which will aid you in being able to output a PGM image. If you are interested in more information, the formal image specification can be found here.
Sample pgm file:
P2 4 4 255 0 33 0 170 0 143 0 0 0 0 63 0 170 0 0 255
P2 4 4 255
The image body contains the actual picture information as a series of greyscale values. Each pixel of the image is a tiny, gray square. In the PGM file, each pixel is defined by a single value representing how intense, or bright, the shade of gray is. So, the first pixel, which has a value of 0, is black, and the last pixel, 255, is white. By varying the levels of the pixel values you can come up with any intensity in-between.
Note that gray values must be separated by a space, but after that any additional whitespace is ignored by the image viewer. In the sample pgm above we used additional whitespace to format the pixel values so that it is easy for a human to understand, but the computer doesn't care if everything is on one line, if there is one line of gray values per line of the image, or some mix. You should not assume one line in the file corresponds to one line in the image.
The example image above would look something like this:
Keep in mind, each square is one pixel, so the real thing is much smaller (the rendered image was blown up by 5000%).
As an aside, while PGM files are easy to view as text
(you can use vim, emacs, or Notepad, for instance), they are highly
inefficient. Most modern image formats use some form of compression
to reduce the amount of information stored (and consequently, their size)
while preserving the image appearance. One modern use for PGM is an
intermediate format when converting images from one type to another.
On lab computers, there are many programs for viewing PGM files. ImageMagick can be invoked on the command line:
$ display image.pgmYou can also XV or GIMP. On your home computers, you may need to download an image viewer such as Irfanview.
To generate a PGM image from an image in your photo library, do the following in GIMP:
$ gimp image.jpg