Home / Alt manpages / pnmflip(1)

  • pnmflip(1)
  • User command
  • linux

Replace pnmflip with pamflip Without Losing Your Image Workflow

You will finish with a current Netpbm command for flipping or rotating PNM images, plus a quick check that proves the output has the expected dimensions and pixel order. On this machine, the installed package is Netpbm 11.05.02-1.1build1. Its pnmflip(1) manual says that pnmflip was replaced in Netpbm 10.13, released in December 2002, and now exists as a compatibility translator to pamflip.

Allow about ten minutes. You need Netpbm, a shell, and a PNM image such as PGM or PPM. The examples write transformed data to a new file or standard output. They do not overwrite the input unless you deliberately redirect output over it, so keep that distinction visible.

1. Check whether an old script still calls pnmflip

Find the legacy command before changing anything:

rg -n '(^|[[:space:]])pnmflip([[:space:]]|$)' ./scripts /etc 2>/dev/null

Use a narrower directory if /etc is not part of your search. This is a read-only check. If you find a command in a script, note its options and whether it reads a filename or standard input. Do not mechanically replace the name until you have checked how many transformations it requests.

Checkpoint

The old command is either absent, or you have a copy of each invocation that needs migrating.

2. Replace one simple flip

For a left-to-right flip, replace the old command with pamflip -leftright. The short form is -lr:

$ pamflip -leftright input.pgm > flipped.pgm
$ pamfile input.pgm flipped.pgm
input.pgm:   PGM ...
flipped.pgm: PGM ...

The ellipses above stand for the dimensions and maximum value reported for your files. pamflip reads the named image and writes the transformed image to standard output. With no input filename, it reads standard input, so this is equivalent:

$ cat input.pgm | pamflip -lr > flipped.pgm

Do not use cat merely for decoration in a script. It is useful here when the image is already arriving through a pipeline; otherwise, passing the filename makes the data flow easier to inspect.

3. Choose the transformation explicitly

The current command requires exactly one transformation option. These are the useful direct replacements:

pamflip transformations
ResultLong optionShort option
Mirror left and right-leftright-lr
Turn top to bottom-topbottom-tb
Transpose rows and columns-transpose-xy
Rotate counterclockwise 90 degrees-rotate90-r90
Rotate 180 degrees-rotate180-r180
Rotate clockwise 90 degrees-rotate270-r270

For example, a counterclockwise quarter-turn is:

$ pamflip -r90 input.ppm > rotated.ppm
$ pamfile input.ppm rotated.ppm

A quarter-turn swaps width and height. A left-right or top-bottom flip keeps both dimensions unchanged. That gives you a useful structural check even before looking at the pixels.

4. Handle old commands with several options

This is the migration trap. Older pnmflip accepted any number of basic flip options and applied them in the order given. Current pamflip accepts one direct transformation option. Running this will fail:

$ pamflip -leftright -topbottom input.pgm > output.pgm
pamflip: You may specify only one type of flip.

For a sequence, use -xform and list the transformations in order:

$ pamflip -xform=leftright,topbottom input.pgm > output.pgm

Keep the order when migrating. Flips and rotations do not always commute, so swapping the names can change the result. The -null option is available when a script computes a transformation and sometimes needs to request no change:

$ pamflip -null input.pgm > unchanged.pgm

Checkpoint

Every new pamflip invocation has exactly one direct transformation, or one -xform sequence. If you see several direct options, stop and convert them to an ordered sequence.

5. Check large-image memory behaviour

Simple left-right and top-bottom flips are relatively straightforward. Transpose and quarter-turn operations access columns and can page heavily when the image is large. If a conversion appears stuck while the machine is thrashing, set -memsize to a realistic number of mebibytes:

$ pamflip -memsize=512 -r90 large.ppm > large-rotated.ppm

The option tells pamflip how much memory is available for the operation. Too high can cause allocation failure or severe paging; too low can make temporary-file processing slower. Start with a conservative estimate of memory available to this job, then measure. No elevated privilege is required, and changing this value does not change the input.

The manual also documents -pagesize, but on current pamflip it has no effect. Do not add it as a performance fix.

6. Verify and keep recovery simple

Check the output file before handing it to another tool:

$ pamfile output.pgm
output.pgm: PGM raw, 3 by 2  maxval 9
$ pnmtopng output.pgm > output.png

The exact format line depends on the input. Netpbm may emit raw PNM even when the input was plain text PNM, so do not use text formatting as your success test. Check that the file is readable and that its dimensions match the selected operation.

If the result is wrong, the original remains available as long as you wrote to a different output path. Remove the generated file only after checking that it is disposable, then rerun with the corrected option or sequence. Do not redirect output to the input filename: a shell opens the destination before pamflip can read all of the source, which can destroy the image.

Done means

  • New work uses pamflip, not pnmflip.
  • A single transformation has the expected option and output dimensions.
  • Several old transformations were migrated to an ordered -xform list.
  • Large quarter-turn jobs use a realistic -memsize only when needed.
  • Input files were preserved and each output passed a pamfile check.