Issue #35 new

transparency and opacity fix

deduikertjes
created an issue

This proposal for enhancement is relative to mapproxy 1.2.0.

Mapproxy does not work well when adding opacity to layers which also have transparent area's. The transparent area's become either semi-transparent black or semi-transparent-white. The problem is described in: http://lists.osgeo.org/pipermail/mapproxy/2012-January/000913.html and http://lists.osgeo.org/pipermail/mapproxy/2012-January/000914.html.

I've created a patch which solves the problem:

{{{

!python

mapproxy/image/init.py: layer_img = layer.as_image() if (layer.image_opts and layer.image_opts.opacity is not None and layer.image_opts.opacity < 1.0): - layer_img = layer_img.convert(img.mode) - img = Image.blend(img, layer_img, layer.image_opts.opacity) + if layer_img.mode == 'RGBA': + alpha = layer_img.split()[3] + alpha = ImageEnhance.Brightness(alpha).enhance(layer.image_opts.opacity) + layer_img.putalpha(alpha) + img.paste(layer_img, (0, 0), layer_img) + else: + layer_img = layer_img.convert(img.mode) + img = Image.blend(img, layer_img, layer.image_opts.opacity) else: if layer_img.mode == 'RGBA': # paste w transparency mask from layer

mapproxy/platform/image.py: Everywhere I've substituted: Image, ImageColor, ImageDraw, ImageFont, ImagePalette, ImageChops by: Image, ImageColor, ImageDraw, ImageFont, ImagePalette, ImageChops, ImageEnhance }}}

I propose to add this to mapproxy.

Comments (0)

  1. Log in to comment