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
On Quarry at Indiana University, they are installed in the
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
ppm). Then there are utilities that convert
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
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
man command to find out more details about each particular
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
ppmquant quantizes the number of colors in the
down to 256 (as many as an 8-bit GIF file can have), and
ppmtogif converts the
pnm file to a GIF file.
| 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
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:
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
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
pnm file (in this case it happens to be a
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:
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.