[Image-SIG] I'm confused by alpha blending.

Ned Batchelder ned at nedbatchelder.com
Tue Mar 21 22:42:07 CET 2006

I'm using PIL to composite a drop shadow onto an image.  The blending 
isn't working the way I would expect.  The drop shadow image itself has 
all black pixels, with all of the interesting stuff happening in the 
alpha channel.  I'm using Image.paste to draw the drop shadow, by 
specifying the shadow png as both the image and the mask.

When I do this on a pure black image, the shadow lightens the pixels!  
For example, a black existing pixel gets a shadow pixel that is black 
with alpha value of 152 decimal. The result should be black (since both 
the source and the destination are black, how can the alpha channel 
lighten the pixel?), but it comes out with a value of 100 decimal.

When I graph the background color against the resulting color (using a 
fixed black shadow pixel with 152 alpha), the result is linear, but as I 
say, it lightens black pixels inexplicably.

Is there something I am doing wrong?

Ned Batchelder, http://nedbatchelder.com

More information about the Image-SIG mailing list