Home / Alt manpages / ppmtopcx(1)

  • ppmtopcx(1)
  • User command
  • linux

Convert PPM Images to PCX Safely with ppmtopcx

You will convert a PPM image into a PCX file, choose the output format when the automatic choice is not suitable, and verify the result without clobbering an existing file. The examples use Netpbm 11.5.2, installed here as Debian package netpbm version 2:11.05.02-1.1build1. Allow about ten minutes if the input image is ready.

You need a readable PPM file, a shell, and permission to create the destination file. The conversion itself normally needs no elevated privileges. This guide does not alter system configuration or install a PCX viewer.

1. Check the installed command

Confirm which executable your shell will run and record the version reported by the installed Netpbm build:

$ command -v ppmtopcx
/usr/bin/ppmtopcx
$ ppmtopcx --version
ppmtopcx: Using libnetpbm from Netpbm Version: Netpbm 11.5.2
... 

The version output includes build details after the library version, so the exact lines can differ between distributions. The important checkpoint is that the command is present and reports the Netpbm version you expect. The local manual page is dated 26 September 2020; the installed executable reports 11.5.2.

2. Convert to the default PCX format

ppmtopcx reads the PPM named on the command line and writes the PCX image to standard output. Redirect that output to a new filename:

$ ppmtopcx /path/to/input.ppm > output.pcx

Do not use sudo just because the source image came from another account. Use it only if your normal account cannot read the source or write the destination, and check the permissions before elevating. Redirection is performed by the shell, so a command such as sudo ppmtopcx input.ppm > output.pcx still writes output.pcx as your user.

The default format depends on the number of colours in the input. With 16 colours or fewer, the program creates a palette PCX and chooses the smallest useful number of planes. With 17 to 256 colours, it creates an 8-bit, one-plane PCX. Above 256 colours, it creates a 24-bit true-colour PCX. This is a format decision, not a resize or quality setting.

Checkpoint: verify that the destination is a PCX file and that the command returned success:

$ printf '%s\n' "$?"
0
$ file output.pcx
output.pcx: PCX ver. 3.0 image data bounding box ..., RLE compressed

The bounding box and colour description depend on the image. If the conversion fails, stop before using the output. A failed redirect can leave a truncated destination behind.

3. Select an explicit colour format

Use -8bit when a reader expects a 256-colour PCX, even if the input uses 16 colours or fewer:

$ ppmtopcx -8bit /path/to/input.ppm > output-8bit.pcx
$ file output-8bit.pcx
output-8bit.pcx: PCX ver. 3.0 image data bounding box ..., 8-bit colour, RLE compressed

Use -24bit when the destination must be true colour, including for an image with 256 colours or fewer:

$ ppmtopcx -24bit /path/to/input.ppm > output-24bit.pcx
$ file output-24bit.pcx
output-24bit.pcx: PCX ver. 3.0 image data bounding box ..., 3 planes each of 8-bit colour, RLE compressed

These options change the PCX representation. They do not add missing detail to an input that has already been reduced to a small palette, and the 24-bit result can be larger.

4. Keep a legacy palette stable

Some older PCX readers ignore the palette stored in the file and assume a particular 16-colour mapping. In that case, use the built-in mapping with -stdpalette:

$ ppmtopcx -stdpalette /path/to/input.ppm > output-standard.pcx

The input must contain only colours from that standard palette. If it contains another colour, the command fails. Netpbm provides pcxstd.ppm as the palette image; use pnmremap with a suitable palette image first when the source needs adapting. Do not combine -stdpalette with -palette=.

For a reader that requires a specific custom ordering, make a PPM palette file with one pixel per palette colour, then pass it with -palette=:

$ ppmtopcx -palette=/path/to/palette.ppm /path/to/input.ppm > output-custom-palette.pcx

Pixels are read left to right, then top to bottom, and become the PCX palette in that order. The aspect ratio of the palette image does not matter. Every input colour must occur in the palette or the conversion fails. Use pnmremap before ppmtopcx if the source contains colours outside the chosen palette.

5. Handle plane and position compatibility

Some old readers accept only particular numbers of planes. For the ordinary 16-colour palette form, -planes=1, -planes=2, -planes=3, or -planes=4 requests a specific value:

$ ppmtopcx -planes=4 /path/to/input.ppm > output-four-planes.pcx

This option is only meaningful for the non-packed 16-colour format. Do not combine it with -24bit, -8bit, or -packed. By default, the program chooses the smallest number of planes that can represent the input colours.

The PCX header also stores an image position. Set it with -xpos= and -ypos=; both default to zero:

$ ppmtopcx -xpos=10 -ypos=20 /path/to/input.ppm > output-positioned.pcx

Position is not padding. It changes the coordinates recorded in the PCX header, whereas pnmpad changes the pixels and dimensions of the image itself. The accepted range for each position is -32767 to 32768.

6. Avoid accidental replacement and recover from a bad output

Shell redirection truncates an existing destination before ppmtopcx starts. Choose a new name while testing, as in output-8bit.pcx. If you must replace a known file, make a backup first:

$ cp --preserve=all output.pcx output.pcx.bak
$ ppmtopcx -24bit /path/to/input.ppm > output.pcx.new
$ file output.pcx.new
$ mv -- output.pcx.new output.pcx

The mv is the state-changing step. If conversion or verification fails, leave the original in place and inspect or remove output.pcx.new deliberately. To undo a completed replacement, restore the backup with mv -- output.pcx.bak output.pcx after checking that the backup is the intended file.

Done means

  • command -v ppmtopcx found the intended Netpbm executable.
  • The conversion returned status 0 and wrote a new destination.
  • file identifies the destination as PCX with the expected colour form.
  • You selected a palette, plane count, or image position only when the receiving reader requires it.
  • No useful source or destination file was overwritten without a deliberate backup and verification.