简体   繁体   English

按列表合并图像 python

[英]Merge images by list python

there is a big list containing paths to images:有一个包含图像路径的大列表:

list= ['home/1.png','home/2.png', ...,'home/100.png']

How to combine them sequentially horizontally?如何将它们水平顺序组合?

I solved the problem!我解决了这个问题!

list_= ['home/1.png','home/2.png', ...,'home/100.png'] list_= ['home/1.png','home/2.png', ...,'home/100.png']

from PIL import Image

images = [Image.open(x) for x in list_]
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.png')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM