Created
November 30, 2021 12:17
-
-
Save asears/409f52a0164719129784ee0efbdac861 to your computer and use it in GitHub Desktop.
Overlay images with PIL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://moonbooks.org/Articles/How-to-overlay--superimpose-two-images-using-python-and-pillow-/ | |
| from PIL import Image | |
| import numpy as np | |
| img = Image.open("data_mask_1354_2030.png") | |
| background = Image.open("background_1354_2030.png") | |
| background.paste(img, (0, 0), img) | |
| background.save('how_to_superimpose_two_images_01.png',"PNG") | |
| # transparency | |
| new_image = Image.new("RGBA", img.size, "WHITE") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from PIL import Image | |
| import numpy as np | |
| img = Image.open("data_mask_1354_2030.png") | |
| print(img.size) | |
| background = Image.open("background_730_1097.png") | |
| print(background.size) | |
| # resize the image | |
| size = (1354,2030) | |
| background = background.resize(size,Image.ANTIALIAS) | |
| background.paste(img, (0, 0), img) | |
| background.save('how_to_superimpose_two_images_02.png',"PNG") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment