(x)html, photography

Two types of pngs

I recently learned that there are basically two different types of png images – indexed and truecolor. Most pngs you find on the internet are probably the truecolor type. The truecolor type uses an rgb format, so each pixel is represented by either 24 bits (8 bit channel depth * 3 channels), or 48 bits (16 bit channel depth). In contrast, indexed images map each pixel onto a 256 (or less) color palette. Wikipedia has a nice graph on this.

Many image tools which produce pngs use the truecolor format. There are advantages to this, as it is a lossless compression format, and it produces nice images. It also includes an option for a separate alpha channel (meaning 32 or 64 bits per pixel), which means you can get some really nice shading. However, the quality of the image comes at a cost – size. Choosing the indexed type of png results in much smaller files, akin to a .gif. Once again, imagemagick can handle this, but by default, actually produces 16bit truecolor pngs. So you have to get the right options. Here is an example of how to convert a pdf into a png in an indexed format.

convert -density 300 -quality 90 -resize 800x600 -type PaletteMatte -depth 8 fig/jfactor.pdf fig/jfactor.png

the 2 crucial options here are -type PaletteMatte and -depth 8. For some applications, it is nice to have a truecolor png. For thumbnails on webpages, you definitely want an indexed image though, since the file size is much smaller. Indexed PNG images will also be smaller than GIF files, because PNG uses a better compression algorithm.