User:Incredio/PPM

PPM example
section

P3 3 2 255 255 0 0 0 255 0 0 0 255 255 255 0 255 255 255 0 0 0
 * 1) the P3 means colors are in ascii, then 3 columns and 2 rows, then 255 for max color, then RGB triplets

The image (expanded):

The above image was expanded without interpolation, using the imagemagick command

convert -sample %6400 tiny6pixel.ppm tiny6pixel.png The P6 format of the same image will store each color component of each pixel with one byte (thus three bytes per pixel) in the order Red, Green then Blue. The file will be smaller but the color information will not be readable by humans: P6 3 2 255 !@#$%^&*_+|{}:"<
 * 1) any comment string

The PPM format is not compressed and thus requires more space and bandwidth than a compressed format would require. For example, the above 192x128 PNG image has a file size of 187 bytes. When converted to a 192x128 PPM image, the file size is 73848 bytes. The PPM format is generally an intermediate format used for image work before converting to a more efficient format, for example the PNG (Portable Network Graphics) format. The PPM format can be converted to PNG without loss of information. The PPM format is certainly simple to write from scratch. The following Python code makes the above example image. It can be adapted to making useful images by reading or constructing an array of numerical data, and programming a conversion of the data to color triplets.

Similar code in C :