For providing maps via WMS over the internet, it is important to generate image files with a small size. Because normally, most of the perceived WMS delay comes from transfering large images files over the internet (and not from map rendering itself). Therefore, QGIS server supports the conversion of png24 and png32 images into png8, therefore generating a file with only 1/3 resp. 1/4 of the original size (but with lower quality). However, until recently, QGIS server was using the default algorithm from the Qt library for conversion to png8, resulting in very ugly png8 images if used with a transparent background and sometimes with shifted colors. Therefore, I decided to implement a better conversion algorithm: the median cut algorithm, which was first described by Heckbert in 1982 ( Paul S. Heckbert, Color Image Quantization for Frame Buffer Display. ACM SIGGRAPH ‘82 Proceedings). This algorithm creates color boxes in 4-dimensional colour space and subdivides at the mean of the largest dimension. It stops if the number of boxes equals the requested number of colors (256 in the case of png8 conversion). First tests show the quality of the converted images are quite good for vector maps. So a performant configuration for a webmap means probably to fetch background rasters as jpg and to overlay vectors as png8 with transparent background.
Let’s see with an example what the conversion from png24 to png8 means in terms of image quality. The first file is a png24 image, 590 KB size:
And this one is the conversion to png8, only 190 KB size.
To test the png8 conversion, you need to have the latest QGIS version from git (or a nightly build tomorrow). Then simply replace the FORMAT paramter in the url with ‘&FORMAT=image/png; mode=8bit’.