It is a common problem that PostScript files (as generated by TeX/LaTeX users) become really large when users try to include pixel mapped images (also referred to as ``sampled images'', ``pixmaps'' or ``bitmaps''). The huge size of the resulting PostScript files is due to the fact, that many converters to Encapsulated PostScript decompress the images.
However, with the right tools and specifying the correct options it is possible to include certain image types (such as JPEG or PNG) retaining compression. This can greatly reduce the size of the resulting PostScript files and thus speed up downloading and displaying.
The article explains which tools and image formats can be used to put images into PostScript without decompression. Moreover, some considerations have been made about which image formats can be used when generating other output formats, namely PDF (Portable Document Format) and HTML, from a LaTeX source.
Pixel mapped images can be included via LaTeX's '\includeimage' (see ) into PostScript output without problems when they are available in (Encapsulated) PostScript format.
Anyway, to put compressed images into the (Encapsulated) PostScript Format, (at least) PostScript Level II must be used. Decompression has to be done by the PostScript viewer/interpreter. Many PostScript viewers seem to be able to do this. Specifically, the following programs/versions were tested. All of them were able to display the PostScript files containing the compressed images (or the DVI files referencing the EPS files):
Basically, the conversion of the images to Encapsulated PostScript can be accomplished in different ways:
The following will concentrate on the usage of different external tools to convert images to PostScript Level II or III.
PostScript Level II supports direct inclusion of JPEG images using the 'DCT' (discrete cosine transform) filter . To display a PostScript file containing images represented with the DCT-filter, the PostScript interpreter must support (at least) PostScript Level 2.
JPEG images can be converted to PostScript with the 'jpeg2ps' program :
This way the compressed image data is included into the PostScript file as is (without decompressing it), which reduces the size of the resulting PostScript file considerably.
PostScript Level 3 supports inclusion of TIFF and PNG images by the following means: The 'LZW' (Lempel-Ziv-Welch) and 'Flate' (zlib/deflate) filters are available for (de)compression. The PNG and TIFF pixel-predictor functions are supported . However, while e.g. PNG images can have Alpha-transparency, PostScript seems to support only Bi-level transparency (using the 'imagemask'-operator).
In contrast, PostScript Level 2 only supports 'LZW'-compression and apparently it doesn't have support for pixel-predictor-functions. Thus, many images won't be compressed as well as it is possible with Level 3's features. Also note that the 'LZW' algorithm is patented, and using it may require paying license fees to the company holding the patent.
PNG and TIFF images can be converted into PostScript Level I, II or III with the program 'bmeps' . To create an EPS file with maximum compression, use:
which creates a Level 3 EPS file using 'flate'-compression for a colored PNG file. Only some small problems occured with the used version of 'bmeps':
For a TIFF file, the call is simply:
'bmeps' is also capable of mapping TIFF and PNG alpha channels to EPS level 3 (Bi-level) image masks.
PNG and TIFF images can be converted into PostScript Level III using the program 'convert' which is part of the ImageMagick graphics tools :
This includes the PNG file without decompressing it into the PostScript file using 'flate'-compression. However, things are not as straightforward as they are for 'jpeg2ps' or 'bmeps':
To reduce the size of a PNG image itself, and to convert from a RGB-type to a palette-type PNG, the program 'pngquant'  can be used.
For a TIFF file, the call is:
TIFF images can be put compressed into a PostScript Level II file with the program 'tiff2ps', which is part of the libtiff tools :
However, the following things should be taken into account:
As with 'latex', pixel mapped images can be included with '\includeimage' (see ). 'pdflatex' supports inclusion of JPEG, PNG and TIFF directly, without the need to convert them before to something like Encapsulated PostScript .
Moreover, PDF can include EPDF (Encapsulated PDF), but cannot include EPS files. However, EPS files may be converted to EPDF using external tools, such as 'ps2pdf' (TODO: must test this).
Using 'tex4ht', an image can be embedded using the following LaTeX code (see ):
Note that the HTML image attributes should define 'width' and 'height' so that Web-browsers can render the page correctly before all images have been loaded.
Most Web browsers can display JPEG and GIF, newer browsers can also display PNG (see ). To achieve compatibility also with older browsers, PNG images could be converted into GIF images. (Note that the 'LZW'-algorithm used to compress GIF images is patented). Formats like TIFF, EPS, EPDF and anything else usually cannot be displayed by Web browsers.
JPEG images can be included without decompression into PostScript Level II, III and PDF and can be displayed by most Web-Browsers.
PNG and TIFF images can be included without de-compression into PostScript Level III and PDF (and with lower compression also in PostScript Level II), but only newer Web-Browsers support displaying PNG images.
TIFF images can be included into PDF, but normally cannot be displayed by Web browsers.
Other image formats may require conversion to be usable for inclusion into PostScript, PDF or HTML. Conversion between various image formats can be done e.g. using ImageMagick's 'convert', which supports hundreds of different graphics formats.
JPEG and PNG generally provide better compression than most other image formats, so it seems reasonable to keep the 'source' images in either of these two formats, depending on which is better suited.
Note that some older printers may not be capable of directly printing PostScript files making use of Level III features. To print Level III files on such a printer, e.g. 'GSView' can be used.
For HTML output, one may choose to use GIF instead of PNG for compatibility with older Web-Browsers.
The versions of the tools to convert images were:
The used TeX versions were:
|||Packages in the `Graphics' Bundle,
|||Keith Reckdahl: Using Imported Graphics in LaTeX
2e (Version 2.0, December 15, 1997),
http://www.ctan.org/tex-archive/info/epslatex.pdf (1.5 MB)
|||Adobe PostScript Language Reference Manual,
Second Edition, 1990,
http://partners.adobe.com/asn/developer/pdfs/tn/psrefman.pdf (3.3 MB)
Sections 3.8.4 (Filters) and 3.13.3 (Details of individual filters, p. 127)
|||jpeg2ps utility - a JPEG to PostScript Level 2 (or
PostScript 3) wrapper,
|||Adobe PostScript Language Reference, Third
http://partners.adobe.com/asn/developer/pdfs/tn/PLRM.pdf (7.4 MB)
Section 3.13.3 (Details of individual filters, p. 129)
|||bmeps - command line tool, library and dvips patch for
|||ImageMagick - Convert, Edit, and Compose Images,
|||libpng - A Basic Introduction to PNG Features,
|||pngquant - utility to quantize and dither 32-bit RGBA
PNGs down to 8-bit (or smaller) RGBA-palette PNGs,
|||TIFF Software - library, tools for TIFF images,
|||The pdfTeX manual,
|||tex4ht - From LaTeX to HTML - Pictures,
|||libpng - Browsers with PNG Support,
If you have comments or suggestions, mail to: