ppmtobmp - convert a PPM image into a BMP file
Minimum unique abbreviation of option is acceptable. You may use double hyphens instead of single hyphen to denote options. You may use white space in place of the equals sign to separate an option name from its value.
This program is part of Netpbm(1).
ppmtobmp reads a PPM image as input and produces a Microsoft Windows or OS/2 BMP file as output.
Before Netpbm 10.85 (December 2018), ppmtobmp ignores this option if the input is PBM and produces a BMP with 1 bit per pixel. With these versions, if you want more than that, use pbmtopgm to convert the PBM to PGM first.
This option does not control what colors are in the output. The colors in the output are exactly those in the input, and the palette you supply must contain at least all the colors that are in the input. You can use pnmremap to adjust your input image so that it contains only colors from your palette.
The palette file is a Netpbm format file with one pixel per palette entry. Each pixel must have a distinct color (no repeats). The order of the BMP palette ppmtobmp generates is the order of the pixels in the palette file, going from top to bottom, left to right.
A BMP palette may have at most 256 colors, so the palette file must have at most 256 pixels.
You may find pnmcolormap useful in generating the palette file. pamseq too.
In the case of grayscale image, if you are processing the BMP image, it
may be convenient for you to have the actual gray values in the raster
part of the image rather than arbitrary indices into a palette. There is
no BMP format specifically for that, but you can achieve it by using a
palette in which each index is equal to the indexed gray value, and then
ignoring the palette when you process the BMP image.
Here is an example of doing that:
$ pamseq 1 255 >mapfile.pgm $ ppmtobmp -mapfile=mapfile.pgm input.pgm >output.bmp
This option was new in Netpbm 10.45 (December 2008).
To get a faithful reproduction of the input image, the maxval of the input image must be 255. If it is something else, the colors in the BMP file may be slightly different from the colors in the input.
Windows icons are not BMP files. Use ppmtowinicon to create those.