[Image-SIG] Paste RGBA to RGBA bug

James Sayer chief at dingogames.com
Fri May 19 02:05:50 CEST 2006


Hi,

I'm trying to paste an RGBA image onto another RGBA image but the 
blending is not working as I would expect it to.

The code is something like this, where src and dst are both RGBA:

src = Image.open( 'img.png' )
dst = Image.open( 'img2.png' )
dst.paste( src, None, src )

What I expect to happen is that the alpha value of 'dst' stays the same. 
However, what actually happens is that the new alpha value is being 
computed by blending 'src' alpha and 'dst' alpha together.

It could be argued that this is the desired behaviour, but I don't think 
that it isn't consistent with other cases of using paste. In fact I 
found a workaround that behaves how I would expect it to. The trick is 
to convert src to a RGB image first, then just use the original src as 
the mask.

src = Image.open( 'img.png' )
dst = Image.open( 'img2.png' )
srcRGB = src.convert( 'RGB' )
dst.paste( srcRGB, None, src )

Actually I did a search and found that this same problem has come up 
before in this thread:
http://www.mail-archive.com/image-sig@python.org/msg00773.html

Cheers,

James Sayer


More information about the Image-SIG mailing list