INQUA Sub-Commission on Data-Handling Methods
Newsletter 16: July 1997
Graphics conversion
K.D. Bennett
Department of Plant Sciences
University of Cambridge
Downing St
Cambridge CB2 3EA, UK
k.d.bennett@queens-belfast.ac.uk
There is a plethora of different formats for graphics files, and it is
frequently useful, even essential, to be able to convert one form to another,
preferably without loss of quality or resolution. Often, conversion is
needed between formats on different computing systems. The aim of this note
is to describe two packages that allow a wide range of useful conversions,
including their availability and use.
The pbmplus package
pbmplus is a toolkit for interconverting various image formats
via a single internal format.
The idea is that to convert among N image
formats, only 2*N conversion filters are needed (into and out of
the internal format), instead of
the N2 that would be needed if a conversion
filter was written separately for each possible pairwise combination of
formats. It was developed by Jef Poskanzer for Unix systems, but has been
ported to MS-DOS.
The system handles a very wide range of formats, including GIF, MacIntosh PICT,
and TIFF. It does not handle PostScript, for which see below.
pbmplus has four internal formats for distinct types of graphics
files:
- PBM (Portable Bitmap) for the conversion of black-and-white
images
- PGM (Portable Graymap) for the conversion of
gray-scale images
- PPM (Portable Pixmap) for the conversion of full-colour
images
- PNM (Portable anymap) for the manipulation of images
of any type.
On Unix systems, the system consists of a large number of conversion programs
each of which takes a filename as input, and sends the converted output
to `standard output'. This normally means that it would be sent to the screen
as raw data, by default. In practice, the output is redirected to file, or
`piped' on to another utility. For example:
- To convert the Macintosh PICT file pollen.pict to ppm format, the command line
would be
picttoppm pollen.pict >pollen.ppm
- To convert the Macintosh PICT file pollen.pict to GIF format,
the sequence could be done to two steps (the one above, then the
conversion from ppm to GIF), or as a single command via a `pipe'
(indicated by the vertical bar symbol |)
picttoppm pollen.pict | ppmtogif >pollen.gif
This is a rather handy way to convert images scanned on a Macintosh system
to the GIF images beloved by WWW pages. Similarly, I used the programs bmptoppm
and ppmtogif to convert Windows BMP files that Adam Walanus sent
me for his article in this issue
(Walanus & Nalepka 1997) into the GIF images
that you will find there.
As well as the conversion filters, the package also includes programs for
graphics file manipulation, including rotation and colour reduction, for
example. I frequently need to convert images from Kodak Photo CD format
to GIF format for WWW use, and I do this with the command sequence:
hpcdtoppm -1 IMAGE.PCD IMAGE.ppm
ppmquant -fs 256 IMAGE.ppm | ppmtogif >IMAGE.gif
(hpcdtoppm, to convert Kodak Photo CD to ppm, is distributed with pbmplus,
but is written by Hadmut Danisch, and works slightly differently.)
ppmquant reduces the number of colours in the file to (in this case)
256 for the GIF format, as Photo CD images may have many thousands of colours.
So-called `transparent' GIF files for use in WWW pages (with no background
colour) can be obtained by using the option `-tranparent white'
(or whatever the background colour is) with ppmtogif.
pbmplus is so close to being a standard utility that it is normally
installed by administrators on Unix systems. If not, it can be obtained by
anonymous ftp to many sites (use archie to find your nearest). A
version for MS-DOS is available, also by anonymous ftp, and included on a
CD-ROM with the book on graphics files by Murray & vanRyper (1994).
On a Unix system, you can find out what conversion filters are available
and how to use them from the man pages (start with man pbmplus).
The Ghostscript / Ghostview package
Aladdin Ghostscript is a program that `interprets' PostScript for
non-PostScript output devices. In practice, this means that it can display
PostScript files on screens, and it can convert it into other
formats, for non-PostScript printers, and other graphics formats (notably
ppm, discussed above). It can be used directly, on the command line
in MS-DOS and Unix, and this is a handy way to carry out most file conversions,
but it is also invoked indirectly by a PostScript viewer called
ghostview (on Unix) or GSview (on MS-Windows and Macintosh).
This viewer also allows some conversions, especially in the MS-Windows
version, but exists primarily to enable viewing of PostScript files before
printing them out. The Macintosh version is more recent than the others, and
still lacks some of their features. Notably, it cannot rotate diagrams, but
this can always be solved by rotating the terminal instead.
Ghostscript, used directly, is complex, and not very user friendly, but it
does work. To give a flavour of it, I use the command sequence below to
convert PostScript files to GIF files for WWW pages, combining use of
Ghostscript with pbmplus:
gs -sDEVICE=ppm -sOutputFile=diagram.ppm diagram.ps
ppmtogif diagram.ppm >diagram.gif
(The Ghostscript program is called `gs' on both Unix and MS-DOS).
Aladdin Ghostscript and the viewer, like pbmplus, is normally
already installed on Unix systems. All versions can be obtained from by WWW to
Aladdin Enterprises. Installation
is reasonably straightforward, but the files are very large, and there are
many of them (ghostscript, the viewer, fonts, at least). It would be difficult
and frustrating to attempt this without direct internet access.
Murray, J.D. & vanRyper, W. 1994. Graphics File Formats. O'Reilly,
Sebastopol, CA.
Walanus, A. & Nalepka, D. 1997. Palynological diagram drawing in
Polish POLPAL for Windows. INQUA Working Group on Data-handling Methods, Newsletter
16.
Copyright © 1997 K.D. Bennett
Home page
Newsletter 16 index
Author index
Subject index
WWW pages by K.D. Bennett