In Unix, what are the netpbm utilities and how do I use them to convert one type of image file to another?

In Unix, the netpbm utilities, an independent revision of an earlier package known as pbmplus, offer a large number of filters for converting just about any image file type into just about any other file type. These utilities are often installed in the directories /usr/local/bin, /usr/local/pbmplus/, or /usr/local/netpbm.

On Quarry at Indiana University, they are installed in the directory /usr/bin.

The sheer number of these utilities precludes a description of each of them, so instead a general overview is presented here. Image conversion with the netpbm utilities usually takes two or more steps. There are utilities that convert a variety of image files into a common format, a pnm file (portable anymap file, including pnm, pbm, pgm, and ppm). Then there are utilities that convert pnm files to a variety of other image formats. For example, if you wanted to convert an SGI rgb file into a GIF format file, you would first convert the rgb file into a pnm file, and then convert the pnm file into GIF format.

Not all of the netpbm utilities are used to convert one thing into another. Some of them do various things that affect an image file itself, such as rotate, scale, or quantize it. Again, you can use the Unix man command to find out more details about each particular command.

Many of the netpbm utilities are designed to be piped together into one long string of commands. The example previously described may also be executed briefly as:

  sgitopnm filename.rgb | ppmquant 256 | ppmtogif > filename.gif

The above string of commands uses three netpbm utilities. sgitopnm converts the rgb file to a pnm file, ppmquant quantizes the number of colors in the pnm file down to 256 (as many as an 8-bit GIF file can have), and ppmtogif converts the pnm file to a GIF file. The | characters in the command line above are pipes, indicating that the output of a command on the left of the | character will be fed into the command on the right. The > character at the end dumps the results of all the previous commands into a file called filename.gif.

As a slightly different example, suppose you want to convert a PostScript file to a GIF format file. First, use the pstopnm command as follows:

  pstopnm filename.ps

This command is a little different from the previous example because it does not involve pipes. Some of the netpbm utilities lend themselves well to pipes, and some of them don't. This is one that doesn't. Instead of passing its conversion down a pipe, it creates a file called filename001.ppm in your current directory. The best way to learn which commands you can pipe together and which commands write out files is by trial and error, or by reading the man page before you use the utility. Now that you have a pnm file (in this case it happens to be a ppm), you can use ppmtogif to convert it into a GIF:

  ppmtogif filename001.ppm > filename.gif

This will create your GIF file. If the above command fails because of errors, it's probable that your PostScript document had too many colors for a GIF. If that's the case, try this instead:

  ppmquant 256 filename001.ppm | ppmtogif > filname.gif

There are a wide variety of these utilities, and while they generally work the same way, they don't all work exactly the same. Together, however, they are a very powerful and efficient set of tools. With a little practice and reference to the manual pages you can get a great deal of use out of them.

For more information and to download the latest release, visit the netpbm home page at:

  http://netpbm.sourceforge.net/

Note: At IU, the UITS central systems may not have the latest netpbm release installed.

At Indiana University, for personal or departmental Linux or Unix systems support, see At IU, how do I get support for Linux or Unix?

This is document afil in the Knowledge Base.
Last modified on 2015-06-23 00:00:00.

  • Fill out this form to submit your issue to the UITS Support Center.
  • Please note that you must be affiliated with Indiana University to receive support.
  • All fields are required.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.

  • Fill out this form to submit your comment to the IU Knowledge Base.
  • If you are affiliated with Indiana University and need help with a computing problem, please use the I need help with a computing problem section above, or contact your campus Support Center.

Please provide your IU email address. If you currently have a problem receiving email at your IU account, enter an alternate email address.