Home / Alt manpages / winicontoppm(1)

  • winicontoppm(1)
  • User command
  • linux

Convert Windows ICO Files to PPM with winicontoppm

An old script still wants PPM output, so winicontoppm pulls one image out of a Windows icon file for it. You can take the first entry, the best-quality one, or every embedded image, and check the result without touching the original icon. The examples use winicontoppm from Netpbm 11.5.2, installed here as package version 2:11.05.02-1.1build1.

Allow about ten minutes. You need a shell, the netpbm package and a readable ICO file. The conversion normally needs no elevated privileges. Use sudo only if the input directory is genuinely unreadable to your account, or if you deliberately choose an output directory that requires it.

1. Check the installed command and input

Confirm which executable will run and check that the source file exists before starting:

$ command -v winicontoppm
/usr/bin/winicontoppm
$ dpkg-query -W -f='${Package} ${Version}\n' netpbm
netpbm 2:11.05.02-1.1build1
$ ls -l /path/to/icon.ico
-rw-r--r-- 1 you you 1234 Sep 28 12:00 /path/to/icon.ico

The size and timestamp in the last line are examples. The useful check is that the path names the ICO you intend to read and that it is readable. If the command is missing, install Netpbm through your normal package-management process rather than copying a binary into the working directory.

Checkpoint: keep the original .ico file. winicontoppm reads it; it does not edit it.

2. Extract the default image to a new PPM

With no selection option, the program extracts the first image in the icon. Its normal output is standard output, so redirect it to a new destination:

$ winicontoppm /path/to/icon.ico > icon.ppm
$ file icon.ppm
icon.ppm: Netpbm image data, 32 x 32, 8-bit/color RGB, rawbits, pixmap

The dimensions in file depend on the first embedded image. The command supports ICO images with 1, 4, 8, 24 and 32 bits per pixel. The installed tool can therefore read 24-bit and 32-bit images; the manual records that support for those depths was added after Netpbm 10.15.

Do not redirect over a useful output by accident. The shell truncates icon.ppm before winicontoppm starts. Pick a new name, or make a backup first:

$ cp --preserve=all icon.ppm icon.ppm.bak
$ winicontoppm /path/to/icon.ico > icon.ppm.new
$ file icon.ppm.new
icon.ppm.new: Netpbm image data, 32 x 32, 8-bit/color RGB, rawbits, pixmap
$ mv icon.ppm.new icon.ppm

If the conversion fails, remove the incomplete icon.ppm.new and the original icon.ppm remains in place. The backup is also a recovery copy. Delete it only after checking the replacement, and only when you are sure it is no longer needed.

3. Select the best or every embedded image

ICO files commonly contain several resolutions and colour depths. Choose explicitly when the first entry is not the one you want:

$ winicontoppm -bestqual /path/to/icon.ico > icon-best.ppm
$ file icon-best.ppm
icon-best.ppm: Netpbm image data, 256 x 256, 8-bit/color RGB, rawbits, pixmap

$ winicontoppm -allicons /path/to/icon.ico icon-all
$ file icon-all_1.ppm icon-all_2.ppm
icon-all_1.ppm: Netpbm image data, 16 x 16, 8-bit/color RGB, rawbits, pixmap
icon-all_2.ppm: Netpbm image data, 32 x 32, 8-bit/color RGB, rawbits, pixmap

-bestqual selects one image, preferring the largest and then the highest bits-per-pixel. -allicons extracts all images. The exact dimensions and file count are properties of your ICO, so treat the output above as a shape to verify, not a promise about your file.

When a destination stem is supplied, the program adds the .ppm suffix. One selected image is written as icon-best.ppm; multiple images are named icon-all_1.ppm, icon-all_2.ppm and so on. An existing file with one of those names may be overwritten, so use a fresh stem or move old results aside first.

4. Put multiple PPM images in one file when needed

Add -multippm when you want all selected PPM images in a single destination file:

$ winicontoppm -allicons -multippm /path/to/icon.ico icon-sequence
$ file icon-sequence.ppm
icon-sequence.ppm: Netpbm image data, 16 x 16, 8-bit/color RGB, rawbits, pixmap

The file contains the selected PPM outputs as a single multi-image PPM stream. Some consumers expect one image only, so use separate numbered files if the next tool does not document support for multiple images. -multippm does not resize, merge or choose one image for you.

5. Export transparency masks separately

Windows icons carry an AND mask containing transparency data. Add -writeands when you need that mask as a separate PBM file:

$ winicontoppm -bestqual -writeands /path/to/icon.ico icon-mask
$ file icon-mask_xor.ppm icon-mask_and.pbm
icon-mask_xor.ppm: Netpbm image data, 256 x 256, 8-bit/color RGB, rawbits, pixmap
icon-mask_and.pbm: Netpbm image data, 256 x 256, 1-bit bitmap

The output names use the destination stem. For multiple images, expect numbered names such as icon-mask_xor_1.ppm and icon-mask_and_1.pbm. The PBM is a mask, not a second colour image. Keep the XOR PPM and its matching AND PBM together if a later workflow needs to reconstruct the icon's transparency behaviour.

6. Diagnose failures without guessing

An error opening the input usually means a wrong path, permissions problem or a file that is not a complete ICO. Check it without changing anything:

$ test -r /path/to/icon.ico && echo readable
readable
$ ls -lh /path/to/icon.ico

If output names are unexpected, check whether you used -allicons, -multippm or -writeands. The default selection is only the first image. The default destination is standard output, while a supplied destination is a filename stem to which Netpbm adds suffixes.

A successful exit status proves that the converter completed, not that a viewer will display the image as intended. Check the PPM or PBM with file, inspect dimensions, and open it with a trusted image tool. If the output is corrupt, return to the untouched ICO and try an explicit selection rather than editing the generated file.

Its own manual calls winicontoppm essentially obsolete, because winicontopam is newer and better. Reach for this one only when you specifically need PPM and PBM output, or compatibility with an existing PPM-based workflow. For a new script, check winicontopam first.

Done means

  • The installed Netpbm version and input path were checked.
  • A new PPM was created and its type and dimensions were verified.
  • You selected first, best-quality or all images deliberately.
  • You understand the destination naming rules and avoided accidental overwrites.
  • Any required AND transparency mask was saved as a matching PBM.
  • The original ICO remains available for recovery or another conversion.