[Tilecache] bad quality with 8bit AGG
PNG images and metaTile=true
Mark Deneen
mdeneen+tiles at saucontech.com
Thu Mar 5 14:29:01 EST 2009
Gregor at HostGIS wrote:
> > Gregor at HostGIS wrote:
> >
>
>> >> run ImageMagick's convert to scale them down to 8
>> >>
>>
> >
> > How rude of me to share the idea but not be specific. :)
> >
> > # watch that linewrap; there's only 1 line here
> > find /tmp/tilecache/parks_and_forests -name '*.png' -ls -exec convert
> > -depth 8 -colors 256 {} {} \;
> >
> > Note that it can take a long time for large datasets. You may want to
> > run this in "screen" or take some other measure to prevent it from
> > stopping if you get disconnected.
> >
> >
>
I do something similar, but using mod_wsgi, python and PythonMagick.
#!/usr/local/bin/python2.6
import PythonMagick
import urllib
def application(environ, start_response):
status = '200 OK'
query = environ["REQUEST_URI"][9:]
data =
urllib.urlopen("http://www.example.com/cgi-bin/mapserv.fcgi?%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]
We've found that 64 colors looks good for our data set. It results in
much smaller png files. The downside to this approach is that it
happens as the requests come in, so you have to have the CPU available
to handle the load. mod_wsgi throttles this, os the server doesn't get
overwhelmed. The advantage it has over Gregor's solution is that it does
it on the fly. Searching through the cache directory and converting the
images might corrupt an image if it is being written by tilecache as
convert converts it. You can get around this by making sure that the
file has a time stamp of a certain age.
The final downside is that PythonMagick is a major pain in the ass to
build. The dependencies are a bit crazy. :-)
Mark
More information about the Tilecache
mailing list