Home / Alt manpages / pnmtile(1)

  • pnmtile(1)
  • User command
  • linux

Tile a PNM Image to Exact Dimensions with pnmtile

pnmtile repeats a PNM image until it fills an output rectangle of the exact width and height you specify, no more, no less. Allow about ten minutes if the input file is ready. The examples use the installed Netpbm 11.5.2 command, package version 2:11.05.02-1.1build1.

You need the netpbm package, a readable PNM image, and write access to the output directory. No example here needs elevated privileges; reach for sudo only if your input or destination is genuinely protected by the host's file permissions.

1. Check the command and input format

Confirm which executable is being used and inspect its installed version. These are ordinary, read-only commands:

$ command -v pnmtile
/usr/bin/pnmtile
$ pnmtile --version 2>&1 | sed -n '1,3p'
pnmtile: Using libnetpbm from Netpbm Version: Netpbm 11.5.2
pnmtile: Built from source dated 2024-03-31 09:09:47

pnmtile reads a PNM image: the Netpbm family of portable bitmap, greymap and pixmap formats, not a PNG or JPEG. Convert first if your source is something else. The command has no pnmtile-specific switches beyond its positional arguments: width, height, and an optional input file.

Checkpoint

Inspect the source before choosing output dimensions.

$ pamfile input.pnm
input.pnm: PPM raw, 320 by 200  maxval 255

The wording varies between Netpbm versions. What you need from it: the input is a PNM image and its dimensions are plausible for the plan you have.

2. Tile to a new output file

Give the desired output width and height in pixels. The input file is optional; leave it out and standard input supplies the image instead.

$ pnmtile 1200 800 input.pnm > tiled-1200x800.pnm
  • Tiled from the top-left corner. If the rectangle is not an exact multiple of the source dimensions, the last repetition is cropped at the right or bottom edge.
  • Output stays PNM. On this version, a plain PBM or PPM input comes out as raw PBM or PPM, so do not expect the textual P1 or P3 spelling to survive.

Standard input works well in a pipeline:

$ pnmtopnm input.pnm | pnmtile 1200 800 > tiled-1200x800.pnm

pnmtopnm only earns its place here when another Netpbm command produces a stream that needs normalising first. If you already have a plain PNM file, pass it straight in.

3. Verify the exact result

Do not just trust the shell command returning successfully. Inspect the output with another Netpbm reader:

$ pamfile tiled-1200x800.pnm
tiled-1200x800.pnm: PPM raw, 1200 by 800  maxval 255

Your own format and maxval may differ; the important check is 1200 by 800. A small, self-contained smoke test proves the same rule without needing a real image file:

$ printf 'P1\n2 1\n1 0\n' | pnmtile 5 3 | pamfile -
-:  PBM raw, 5 by 3

The one-row, two-pixel source is repeated across five columns and three rows. Output dimensions describe the requested rectangle, not the number of whole copies that happened to fit.

4. Protect an existing destination

Warning

Shell redirection with > truncates its destination before pnmtile even starts, which matters if a conversion fails or the dimensions were mistyped. When replacing a file that matters, write to a temporary name, verify it, then rename it into place:

$ pnmtile 1200 800 input.pnm > tiled-1200x800.pnm.new
$ pamfile tiled-1200x800.pnm.new
tiled-1200x800.pnm.new: PPM raw, 1200 by 800  maxval 255
$ mv -- tiled-1200x800.pnm.new tiled-1200x800.pnm

That final mv is the deliberate, potentially destructive step: replacing the old destination. If the command or verification fails, leave the original alone and remove only the incomplete .new file once you have checked its path. Need a reversible replacement across filesystems, or a directory with odd rename behaviour? Make a backup first:

$ cp --preserve=all tiled-1200x800.pnm tiled-1200x800.pnm.bak

Keep that backup until the new image has been checked visually, or by the next tool in your workflow. Removing it is the irreversible step.

5. Diagnose failed runs

A non-positive dimension is rejected. The installed command reports an error and exits non-zero for zero width, for example:

$ pnmtile 0 800 input.pnm > failed.pnm
pnmtile: Width argument must be a positive number.  You specified 0.
$ printf 'exit status: %s\n' "$?"
exit status: 1
  • Do not treat a created failed.pnm as success: redirection can create an empty or partial file before the command fails. Check the exit status straight away.
  • Input unreadable? Check the path and permissions with ls -l and test -r; running the operation as root just hides the real permission mistake.
  • Wrong dimensions in the output? Check the two positional numbers and rerun to a new destination.
  • Right dimensions but the image looks wrong? Confirm the source itself is what you think it is, and that your viewer or converter actually supports its PNM variant. pnmtile does not resize, crop to a smaller centre, or produce a compressed format.

Done means

  • Version checked: pnmtile and its Netpbm version.
  • Input confirmed: a readable PNM image.
  • Dimensions supplied: output width and height given as positional arguments.
  • Output verified: pamfile confirms the exact dimensions.
  • Existing destination protected: nothing was replaced until the new file passed verification.
  • No privilege creep: no elevated privileges or persistent system changes were needed.