[Tutor] Pasting an image with transparency

Terry tvbare at gmail.com
Thu Jun 1 15:34:37 EDT 2017


Slackware 14.2 64-bit
Python 2.7.13

I am trying to automate some photo processing by pasting a
sig or watermark. The sig image is a .png with transparency
but when it pastes it does so with a black background. Is there
a way to paste with transparency?



from PIL import Image
from PIL import ImageEnhance

fname = "sample.jpg"

im = Image.open(fname)
print(im.format, im.size, im.mode)

out = im.resize((1068, 712))

enh = ImageEnhance.Sharpness(out)
enh = enh.enhance(2.5)

sig = 
Image.open("/home/tvbare/pics/recent_pics/sigs/opi_sig_landscape.png")
print(sig.format, sig.size, sig.mode)
box = (768, 616, 1018, 662)
enh.paste(sig, box)

enh.show()

-- 
     Terry "Hoots"

          To stay young, never lose your sense of wonder.


                              *****
              My main photo gallery can be seen at:
            <URL:http://www.flickr.com/photos/tvbare/>

               I also keep a secondary gallery at:
<URL:http://www.facebook.com/pages/Osage-Plains-Images/300412117042>

                              *****



More information about the Tutor mailing list