Hi,

I'll just patch mapnik's ogcserver (if you are using it, of course). We are 
using a copy of ogcserver for each wms service instead of a global installed 
one. This means there is no problem in doing such an ugly hack :) because it 
will affect just that service.

The image won't hit the disk until cached and it will also save you the hassle 
of running a script afterwards. Tell me if the performance is acceptable, 
perhaps we can make a patch until support is added to mapnik.

File common.py:

class WMSBaseServiceHandler(BaseServiceHandler):

    def GetMap(self, params):
        m = self._buildMap(params)
        im = Image(params['width'], params['height'])
        render(m, im)
        format = PIL_TYPE_MAPPING[params['format']]
        import PIL, StringIO
        img = PIL.Image.open(StringIO.StringIO(im.tostring(format)))
        img = self.reduce_opacity(img, 0.5)
        buf = StringIO.StringIO()
        img.save(buf, format=format)
        return Response(params['format'].replace('8',''), buf.getvalue())

    def reduce_opacity(self, im, opacity):
        import ImageEnhance
        """Returns an image with reduced opacity."""
        assert opacity >= 0 and opacity <= 1
        if im.mode != 'RGBA':
            im = im.convert('RGBA')
        else:
            im = im.copy()
        alpha = im.split()[3]
        alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
        im.putalpha(alpha)
        return im


> -----Mensaje original-----
> De: [email protected]
> [mailto:[email protected]] En nombre de
> Dražen Odobašic
> Enviado el: martes, 31 de agosto de 2010 14:42
> Para: [email protected]
> Asunto: [Mapnik-users] Mapnik map opacity
>
> Hi,
>
> does Mapnik support setting rendered map opacity, for
> instance i would
> like to have rendered images with 50% opacity?
>
> Thank you
> _______________________________________________
> Mapnik-users mailing list
> [email protected]
> https://lists.berlios.de/mailman/listinfo/mapnik-users
>
_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users

Reply via email to