Skip to content

Instantly share code, notes, and snippets.

@simrit1
Forked from MaxvanHaastrecht/image_grid.py
Created January 24, 2022 05:39
Show Gist options
  • Select an option

  • Save simrit1/3356434cbf10c8665cdfe1746ff3e30c to your computer and use it in GitHub Desktop.

Select an option

Save simrit1/3356434cbf10c8665cdfe1746ff3e30c to your computer and use it in GitHub Desktop.
Creating a grid of images
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