How to produce 8bits AGG homemade colors palette with Mapserver

The format of the output image affects the quality and size of the image to be transferred to the client on the web. We are always trying to minimize the size without losing image quality. With Mapserver, we can use the format AGG (24bit or 32bit PNG) of high quality although it's also a format that produces larger image size(in Kb). But, it's possible to force Mapserver to produce images of excellent qualities AGG 8bit format. The default image format output in Mapserver is 8bit PNG format (256 colors). To test a 24bits or 32bits format, you must overwrite the default format in your mapfile with this in your MAP tag. OUTPUTFORMAT    NAME "png"    MIMETYPE "image/png"    DRIVER "GD/PNG"    EXTENSION "png"    #--IMAGEMODE RGB #-- Driver PNG 24bit    IMAGEMODE RGBA #-- Driver PNG 32bit    TRANSPARENT ON END The default AGG format in Mapserver is a 24bits driver but you can use a 8bits driver. This type of driver in your mapfile will cause a slower performence of Mapserver. You can specify a predefined colors palette to improved performance and get accurate colors of your map. To build your homemade colors palette, you have first to produce a 8bits AGG image by mapserver with this driver in your mapfile: OUTPUTFORMAT    NAME "png8bitaggauto"    DRIVER "AGG/PNG"    MIMETYPE "image/png"    IMAGEMODE "pc256"    EXTENSION "png"    FORMATOPTION "TRANSPARENT=ON"    FORMATOPTION "INTERLACE=OFF"    FORMATOPTION "QUANTIZE_FORCE=ON"    FORMATOPTION "QUANTIZE_COLORS=256" END I suggest to produce more than just one image. Get images from multiple scales and different sectors of your WMS to get every colors. After, build a mosaic all images with an imaging tool like Microsoft Paint or Gymp. Finally, use gdalinfo to get your palette colors and paste them in a ASCII file. To use your new palette colors and realy improve your Mapserver AGG image output, add this driver specification in your mapfile(in MAP tag) #-- Driver AGG 8bits OUTPUTFORMAT    NAME "png8bitsagg"    DRIVER "AGG/PNG"    MIMETYPE "image/png"    IMAGEMODE "rgba"    EXTENSION "png"    FORMATOPTION "TRANSPARENT=ON"    FORMATOPTION "PALETTE_FORCE=TRUE"    FORMATOPTION "PALETTE=E:ms4wpalpal_agg256.txt"    FORMATOPTION "INTERLACE=OFF" END