[Image-SIG] Paste with alpha not working correctly
Helge
image-sig at online.de
Sat Aug 28 20:07:05 CEST 2010
Hello Members,
while playing around with PIL I went into a problem with alpha blending:
> import Image
> bg=Image.new("RGBA",(100,100),(255,0,0,0)) # background red, 100% transparent
> bg.save("bg.png") # will be transparent
> bg.save("bg.jpg") # will be red as alpha is removed
> fg=Image.new("RGB",(100,100),"white")
> fg.save("fg.png")
> mask=Image.new("L",(100,100),0)
> for x in range(100):
> for y in range(100):
> mask.putpixel((x,y),x*255/100) # gradient mask
> mask.save("mask.png")
> comp=bg.copy() # create copy (not required)
> comp.paste(fg,(0,0),mask) # should blend from transparent to white
> comp.save("comp.png") # but is tinted pink
Of course usually I don't use colored bg (this is only for visualization
here). The effect will be also visible if colored images are pasted into
a black bg with mask and then the saved image is viewed on top of a
white bg (pasted image will have a dark halo).
Is this a library problem or am I doing something wrong?
Best Regards,
Helge
More information about the Image-SIG
mailing list