Boxes images
- This time we will create a box into a box image with two different images
- we will also save the file as a png into a directory created by the program itself
from PIL import Image import os # SQUARE 1 big = Image.new("RGB",(200,200),'red') # SQUARE 2 little = Image.new("RGB",(100,100),'yellow') # Let's merge the 2 into 1 # to put it in the middle...let it past at the half of the difference # 200-100= 100 100/2 is 50 so we start at 50,50 big.paste(little,(50,50)) # Let me create an img directory (if it is doesn't exist) if "img" not in os.listdir(): os.mkdir("img") # SAVE AND SHOW RESULT big.save("img/square2.png") print("The pic has been saved in img/") big.show()
out[]: The pic has been saved in img/
If you use python notebook and you want to display the image in the notebook:
from IPython.display import display display(big)
...
Comments
Post a Comment