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.

Join 165 other subscribers

archives

  • 2024 (10)
  • 2023 (8)
  • 2022 (15)
  • 2021 (19)
  • 2020 (1)
  • 2019 (1)
  • 2018 (2)
  • 2017 (1)
  • 2016 (2)
  • 2015 (5)
  • 2014 (5)
  • 2013 (2)
  • 2011 (7)
  • 2010 (10)
  • 2009 (50)
  • 2008 (28)
  • 2007 (31)
  • 2006 (8)

Category