Python library: Pillow

adds image processing capabilities to your Python interpreter.

Library resources
PyPI https://pypi.org/project/Pillow/
Github https://github.com/python-pillow/Pillow
Documentation https://pillow.readthedocs.io/en/stable/index.html
Homepage https://python-pillow.org/

Getting Started

pip install Pillow

to manage .heic files (from iOS), also need to install pillow-heif:

pip install pillow-heif

Usage

Overlay images

To overlay two images in python, a solution is to use the pillow function paste(), example:

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")

Note: to make white pixels transparent a solution is to add the following line:

new_image = Image.new("RGBA", img.size, "WHITE")

source: https://www.moonbooks.org/Articles/How-to-overlay--superimpose-two-images-using-python-and-pillow-/

Resources

links

social