Tenho cerca de 250 arquivos .png em um diretório.
Preciso concatená-los verticalmente do python.
Aqui está o código que tenho até agora.
list_im = [] <- this is the list of .png files <- How do I populate it if I have 250 files in one directory?
imgs = [ Image.open(i) for i in list_im ]
# pick the image which is the smallest, and resize the others to match it (can be arbitrary image shape here)
min_shape = sorted( [(np.sum(i.size), i.size ) for i in imgs])[0][1]
imgs_comb = np.hstack([i.resize(min_shape) for i in imgs])
# for a vertical stacking it is simple: use vstack
imgs_comb = np.vstack([i.resize(min_shape) for i in imgs])
imgs_comb = Image.fromarray( imgs_comb)
imgs_comb.save('concatenatedPNGFiles.png' )
Como preencho list_im
com 250 arquivos .png em python?
Eu faria algo assim:
Com esta modificação, list_im conterá todos os caminhos de arquivo PNG no diretório especificado e o restante do seu código deverá funcionar conforme o esperado.