[Image-SIG] transparency issues
Joerg Baumann
Joerg.Baumann@stud.informatik.uni-erlangen.de
Fri, 6 Oct 2000 23:09:43 +0200 (MET DST)
On Fri, 6 Oct 2000, Jeff Simpson wrote:
> I'm using PIL 1.1 to create some simple images, with lines and
> rectangles. I am having a problem making the background for the image
> transparent. I was wondering if anyone knows if these features work
> (i.e. do transparency masks work in 1.1?). If so, can someone post a
> small example snippet for making a region transparent?
>
> Thanks
This works for me (PIL 1.1 Linux)
import Image
#new image
img=Image.new("RGB",(100,100),(0,100,200))
#add alpah channel
img=img.convert("RGBA")
#draw violet background
img.paste((100,0,200,255),(0,0,100,100))
#make center transparent
img.paste((0,0,0,0),(20,20,80,80))
# save as png (png works, tif and gif not, tga?)
img.save("alpha.png")
bye
joerg
Joerg Baumann joerg.baumann@stud.informatik.uni-erlangen.de
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Beware of bugs in the above code; I have only proved it correct,
not tried it.
Don Knuth