Create two images and merging them
In this episode we will still try to make some very simple use of PIL and Image to create and modify images.This time we will create two images, two simple square images 50x50 and then we will overlay them one over another creating a third image. We will also display the result. First thing first: let's import the modules we need.
1. Let's see the code for 'normal' use of python
2. Now let's see the code to be used in Jupyter notebook
from PIL import Image as Img from IPython.core.display import Image, display
Then we create the first image: the black box
black = Img.new('RGB',(50,50),'black')
display(black)
Now the red one of the same size
red = Img.new('RGB',(50,50),'red')
display(red)
Now we blend them
red = red.convert("RGBA")
black = black.convert("RGBA")
new = Img.blend(red,black,0.5)
display(new)
Comments
Post a Comment