[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
I've created a patch which solves the problem:
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()
+ alpha = ImageEnhance.Brightness(alpha).enhance(layer.image_opts.opacity)
+ img.paste(layer_img, (0, 0), layer_img)
+ layer_img = layer_img.convert(img.mode)
+ img = Image.blend(img, layer_img, layer.image_opts.opacity)
if layer_img.mode == 'RGBA':
# paste w transparency mask from layer
Everywhere I've substituted:
Image, ImageColor, ImageDraw, ImageFont, ImagePalette, ImageChops
Image, ImageColor, ImageDraw, ImageFont, ImagePalette, ImageChops, ImageEnhance
I propose to add this to mapproxy.
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)
This should now work with the upcoming MapProxy 1.6 release and Pillow 2.0.