Skip to content
Advertisement

How to merge a transparent png image with another image using PIL

I have a transparent png image foo.png and I’ve opened another image with:

JavaScript

Now what I need is to merge foo.png with foo2.png.

(foo.png contains some text and I want to print that text on foo2.png)

Advertisement

Answer

JavaScript

First parameter to .paste() is the image to paste. Second are coordinates, and the secret sauce is the third parameter. It indicates a mask that will be used to paste the image. If you pass a image with transparency, then the alpha channel is used as mask.

Check the docs.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement