Comment 17 for bug 487435

Revision history for this message
Juho Vepsäläinen (bebraw) wrote :

I noticed that the watermark image mode is set to "P" (point? is there PIL doc for modes?). As a result the alpha channel produced was totally wrong (squeezed horizontally). I managed to bypass/fix the issue with following hack:

def reduce_opacity(im, opacity):
    ...

    if opacity < 0 or opacity > 1:
        return im

    if im.mode == 'P':
        im = im.convert('RGBA')

    alpha = get_alpha(im)
    alpha = ImageEnhance.Brightness(alpha).enhance(opacity)
    put_alpha(im, alpha)
    return im

As the algorithm works just fine with RGBA it seemed most straightforward to handle the conversion in this stage.