transparency and opacity fix #2

Closed
olt opened this Issue May 15, 2012 · 2 comments

Projects

None yet

2 participants

@olt
Member
olt commented May 15, 2012

[imported from https://bitbucket.org/olt/mapproxy/issue/35/transparency-and-opacity-fix]
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.

@bhubergeomer

Thanks for addressing this issue.
The problem still exists in version 1.5.
Will there be a patch for this version too? (the data structure seems to have changed, so this patch is no longer appropriate)
.

@olt
Member
olt commented May 2, 2013

This should now work with the upcoming MapProxy 1.6 release and Pillow 2.0.

@olt olt closed this May 2, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment