You can easily convert such a text file to a PGM file by adding some header information using a text editor.
For example, the following PGM file is an 8x8 image containing 2x2 black and white checkerboard.
P2 8 8 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0
Here, P2 defines the type of image (Portable greymap in ASCII), the next line defines the width and height and the third line defines the maximum grey level. The remaining lines are the actual image data.
PGM is one of the Netpbm formats, which have surprisingly good support on most operating systems and graphics applications due to their very simple formats.