[Tilecache] Mapserver AGG/PNG paletted image distorted when using metatile due to limitation of PIL - works fine with pil-117-fastpng

SQ9MEV groups at sq9mev.info
Mon Nov 21 16:06:01 EST 2011


W dniu 20.11.2011 22:18, Ivan Mincik pisze:


> Tonnhofer) are now merged in development version of PIL.  As far as I
> know, there is no better way how to work with paletted PNGs, than to
> use latest dev PIL. To be safe, You can always build PIL-dev localy,

Works well with http://hg.effbot.org/pil-2009-raclette/overview which is 
PIL-dev branch i thing, but Layers.py still needs to be patched (second 
patch).

The reason is:
im = Image.open('static/tiles/facility/01/000/000/001/000/000/001.png')
im.info['transparency'].__class__
<type 'list'> # 256 ints

 >>> subimage = im.crop((2,2,254,254))
 >>> subimage
<PIL.Image._ImageCrop image mode=P size=252x252 at 0x93DADEC>
 >>> subimage.info
{} #info is empty, but saved PNG (transparency channel is saved)
Reopening subimage shows info with transparency.

In subimage saved with transparency set to im.info['transparency'] 
transparency is stripped, and subimage saved that way cannot be reopened:

   File "[...]/site-packages/PIL/Image.py", line 2006, in open
     raise DecodeError("cannot identify image file")
DecodeError: cannot identify image file
 >>> Image.open('static/saved_w_transparency.png')

Saying "transparency is stripped" i meen background of 
saved_w_transparency.png is black - its obovoius looking at
  PngImageFile._save(), line 541 in PIL/PngImagePlugin.py pil-2009-raclette.

Pngcheck says both files are OK, but saved_w_transparency.png has all 
0xff in tRNS. Strange, that saved_w_transparency.png


Its too much for me as for today, but i think TileCache needs some 
improovement to work with paletted png8 with transparency, it can not 
call save vith transparency, as it will be degraded do 0xff - in my case 
resulting black background, which is ofcourse unacceptable.

-- 
Bartek


More information about the Tilecache mailing list