Created
September 19, 2021 13:47
-
-
Save MaxvanHaastrecht/16ed6443b85181d0d0f2d137a8e1495f to your computer and use it in GitHub Desktop.
Creating a grid of images
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 | |
| # Load created images; for example 4 | |
| amsterdam = Image.open('Amsterdam.png') | |
| hague = Image.open('The_Hague.png') | |
| rotterdam = Image.open('Rotterdam.png') | |
| utrecht = Image.open('Utrecht.png') | |
| # Retrieve width and height original images | |
| width = amsterdam.size[0] | |
| height = amsterdam.size[1] | |
| # Create new image, twice as large in both dimensions | |
| new_im = Image.new('RGB', (width*2,height*2)) | |
| # Paste images in new image | |
| new_im.paste(amsterdam, (0,0)) | |
| new_im.paste(hague, (width,0)) | |
| new_im.paste(rotterdam, (0,height)) | |
| new_im.paste(utrecht, (width,height)) | |
| # Show the new image of a grid of cities | |
| new_im.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment