Skip to content

Instantly share code, notes, and snippets.

@EckoTan0804
Created July 5, 2021 09:24
Show Gist options
  • Save EckoTan0804/838d99186b53599792674912e2f8758e to your computer and use it in GitHub Desktop.
Save EckoTan0804/838d99186b53599792674912e2f8758e to your computer and use it in GitHub Desktop.
Concat image horizontally
from PIL import Image
images = [Image.open(x) for x in ['Test1.jpg', 'Test2.jpg', 'Test3.jpg']]
widths, heights = zip(*(i.size for i in images))
total_width = sum(widths)
max_height = max(heights)
new_im = Image.new('RGB', (total_width, max_height))
x_offset = 0
for im in images:
new_im.paste(im, (x_offset,0))
x_offset += im.size[0]
new_im.save('test.jpg')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment