Kombinieren Sie mehrere verschiedene Bilder aus einem Verzeichnis zu einer Leinwand im Format 3x6

Ich gehe zu Bildern eines Verzeichnisses. Ich möchte aus diesen Bildern eine 3x6-Leinwand erstellen, ein neues Bild, das die Bilder dieses Verzeichnisses nebeneinander in einem einzelnen Bild / Leinwand anzeigt. Jedes Bild muss ein anderes Bild sein. Seite an Seite. -

Ich habe den folgenden Code. Es wird versucht, die Bilddateinamen aus einem Verzeichnis zu lesen, das in einer Liste gespeichert ist. Dann wird versucht, jedes Bild in eine 3x6-Leinwand zu kopieren / zu kombinieren. Das Ergebnis, das ich will, passiert jedoch nicht. Was mache ich falsch?

import Image
import os
import PIL
import glob
import matplotlib.pyplot as plt

# path
path = "/media/"
listing = os.listdir(path)

# getting all path+filename in a list
npath=[]
im=[]
for infile in listing:
  im.append(infile)
  npath.append(os.path.join(path, infile))

#creates a new empty image, RGB mode, and size 400 by 400.
new_im = Image.new('RGB', (2100,2400))


#Here I resize my opened image, so it is no bigger than ****
#Iterate through a grid with some spacing, to place my image
for i in xrange(0,2100,700):
    for j in xrange(0,2400, 400):
        for imagefile in npath:
            im=Image.open(imagefile)
            im.thumbnail((1000,1000))
            #paste the image at location i,j:
            new_im.paste(im, (i,j))
            new_im.show()
#saving
new_im.save('/media/test.png')

Die Lösun

import Image
import os
import PIL
import glob
import matplotlib.pyplot as plt

# path
path = "/media/"
listing = os.listdir(path)


# getting all path+filename in a list
npath=[]
im=[]

for infile in listing:
  im.append(infile)
  npath.append(os.path.join(path, infile))

#creates a new empty image, RGB mode, and size 400 by 400.
new_im = Image.new('RGB', (2500,3000))

for i in xrange(0,2500,800):
    for j in xrange(0,3000, 500):
        im=Image.open(npath.pop(0))
        im.thumbnail((1000,1000))
        #paste the image at location i,j:
        new_im.paste(im, (i,j))
    new_im.save('/media/test.png')