[Tilecache] Meta Tiled paletted images - PIL issue

mdeneen+tiles at saucontech.com mdeneen+tiles at saucontech.com
Fri Oct 23 12:05:45 EDT 2009


I'm sorry if I may have missed something, but this is how I currently "optimize" png files w/TileCache:


My url in tilecache.cfg goes to a "quantize" wsgi handler, which is written in Python and PythonMagick


#!/usr/local/bin/python2.6

import PythonMagick
import urllib

def application(environ, start_response):
        status = '200 OK'
        query = environ["REQUEST_URI"][10:]
        data = urllib.urlopen("http://www.example.com/mapserv?%s" %query)
        blob = PythonMagick.Blob(data.read())
        image = PythonMagick.Image(blob)
        image.quantizeColors(64)
        image.quantizeDither(False)
        image.quantize()
        image.write(blob)
        response_headers = [('Content-type', 'image/png'), ('Content-Length', str(blob.length()))]
        start_response(status, response_headers)
        return [blob.data]

if __name__ == '__main__':
    from flup.server.fcgi import WSGIServer
    WSGIServer(application).run()


This results in an 8 bit png file with 64 colors.  It's not perfect; the color map from PNG to PNG may be different, depending on the other colors in the image.  My next step is to calculate a global color map and quantize to those colors only.  I don't believe this will be terribly difficult.

So, TileCache calls quantize which calls (in our setup) mapserv with the appropriate parameters.  The image returned from mapserv is quantized to an 8 bit image with 64 colors

file ./04/000/000/040/000/000/125.png
./04/000/000/040/000/000/125.png: PNG image data, 256 x 256, 8-bit colormap, non-interlaced


Best Regards,
Mark Deneen
Saucon Technologies

----- "Ivan Mincik" <ivan.mincik at gista.sk> wrote:

> On Friday 23 October 2009, you wrote:
> > I don't think many programs/libraries work with paletted
> transparency in
> > PNGs. Nor does PIL. So I'm just writing to confirm that this is a
> missing
> > feature of PIL.
> > Tibor
> 
> No solution found also after writing to PIL mailing list, so we can
> not use nice optimized images produced by UMN Mapserver.
> We decided to produce RGBA images from Mapserver and write a "patch" 
> to Tilecache to optimize images just after creation using external
> tools like pngnq of optipng.
> 



More information about the Tilecache mailing list