There are dozens of formats used for graphics files across the computer industry. There are tiff files, PICT files, and gif files. There are different formats for displaying on different hardware, different formats for printing on different printers, and then there are the internal formats used by graphics programs. This means that importing a graphics file from one platform to another (or from one program to another) can be a large undertaking, requiring a filter written specifically to convert from one format to the next.
Go to http://examples.oreilly.com/upt3 for more information on: netpbm
The netpbm package can be used to convert between a wide variety of graphics formats. netpbm evolved from the original Portable Bitmap Package, pbmplus, written by Jef Poskanzer. A group of pbmplus users on the Internet cooperated to upgrade pbmplus; the result was netpbm. netpbm has relatively recently seen some active development again on SourceForge, and its current home page is http://netpbm.sourceforge.net.
The idea behind pbm is to use a set of very basic graphics formats that (almost) all formats can be converted into and then converted back from. This is much simpler than having converters to and from each individual format. These formats are known as pbm, pgm, and ppm: the portable bitmap, graymap, and pixmap formats. (A bitmap is a two-dimensional representation of an image; a graymap has additional information encoded that gives grayscale information for each bit; a pixmap encodes color information for each bit.) The name pnm is a generic name for all three portable interchange formats (with the n standing for "any"), and programs that work with all three are said to be "anymap" programs.
The netpbm package contains well over a hundred conversion programs. There are three basic kinds of programs:
Programs that convert a graphics file to one of the pnm formats. For example, if I had a tiff file and wanted to convert it to PostScript, I might start the process by using tifftopnm:
% tifftopnm Hobbes.tiff > Hobbes.pnm
Programs that convert from one of the pnm formats to another format. For example, if I wanted to convert the Hobbes.pnm file directly to PostScript, I could use pnmtops:
% pnmtops Hobbes.pnm > Hobbes.ps
Programs used to manipulate the image in pnm format. For example, if I wanted to crop the image, I could use pnmcut before I converted the file to PostScript and printed it:
% tifftopnm Hobbes.tiff > Hobbes.pnm % pnmcut 10 10 200 200 Hobbes.pnm > Hobbes.cut % pnmtops Hobbes.cut > Hobbes.ps % lpr Hobbes.ps
Or, on one command line (and without cluttering your disk with intermediary files):
% tifftopnm Hobbes.tiff | pnmcut 10 10 200 200 | pnmtops | lpr
I frequently like to create X11 (Section 1.22) bitmaps out of pictures in newspapers or magazines. The way I do this is first to scan the picture in on a Macintosh and save it as tiff or PICT format. Then I ftp (Section 1.21) the file to our Unix system and convert it to pnm format, and then use pbmtoxbm to convert it to X bitmap format. If the picture is too big, I use pnmscale on the intermediary pnm file. If the picture isn't right-side-up, I can use pnmrotate and sometimes pnmflip before converting the pnm file to X11 bitmap format.
There are far too many programs provided with the netpbm package to discuss in detail, and some of these formats are ones that you've probably never even heard of. However, if you need to fiddle with image files (or, now, video files!), netpbm almost certainly has a converter for it. Take a peek through the documentation sometime.
Copyright © 2003 O'Reilly & Associates. All rights reserved.