2 years ago

#44948

test-img

Darkling

Python Code Image Stitching not working - Mac M1

so a friend of mine sent me this code that worked for him to stitch images together vertically. However, when I try to run it, it gives me this:

Traceback (most recent call last):
  File "/Users/usr/Downloads/Test/Concat.py", line 15, in <module>
    final = Image.new('RGB', (images[0].width, totalHeight))
IndexError: list index out of range 

How can I resolve this?

Here's my code:

import os

from PIL import Image
from os import listdir
from os.path import isfile

files = [f for f in listdir() if isfile(f)]

images = []
totalHeight = 0
for file in files:
    if file.lower().endswith(('.png', '.jpg', '.jpeg', '.tiff', '.bmp', '.gif')):
        images.append(Image.open(file))
        totalHeight += images[-1].height
final = Image.new('RGB', (images[0].width, totalHeight))
runningHeight = 0
for im in images:
    final.paste(im, (0, runningHeight))
    runningHeight += im.height
final.save("Concat.png")

Thanks in advance.

python-3.x

macos

image-stitching

0 Answers

Your Answer

Accepted video resources