[Tutor] Pasting an image with transparency
Terry
tvbare at gmail.com
Fri Jun 2 14:54:43 EDT 2017
On 06/02/2017 08:31 AM, Peter Otten wrote:
> Terry wrote:
>
> We read the docstring so you don't have to ;)
>
I have to remember to utilize available help functions... my bad.
>>>> from PIL import Image
>>>> image = Image.open("sample.jpg") # some random pic I have lying around
>>>> help(image.paste)
> Help on method paste in module PIL.Image:
>
> paste(im, box=None, mask=None) method of PIL.JpegImagePlugin.JpegImageFile
> instance
>
> [...]
> Note that if you paste an "RGBA" image, the alpha band is
> ignored. You can work around this by using the same image as
> both source image and mask.
> [...]
>
> So let's try that. (Since I don't have a transparent picture handy I'm using
> a copy of <https://raw.githubusercontent.com/python-pillow/Pillow/master/Tests/images/transparent.png>.)
>
>>>> stamp = Image.open("transparent.png")
>>>> image.paste(stamp, (0, 0), mask=stamp)
>>>> image.show()
> Seems to work...
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
I first posted my question to the image-sig list but never got a reply.
Awesome! Thank you for responding.
--
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