2 回答
TA贡献1830条经验 获得超9个赞
我希望以下解决方案是您正在寻找的
source_folder1 = "a"
source_folder2 = "b"
target_folder = "Image_Merged"
for img_no in range(1,n+1):
img1 = source_folder1+"_"+str(img_no)+".jpg"
img2 = source_folder2+"_"+str(img_no)+".jpg"
images = [Image.open(x) for x in [img1, img2]]
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(target_folder+"/target_folder_"+str(img_no)+".jpg")
TA贡献1836条经验 获得超13个赞
几乎没有变化
from PIL import Image
source_folder1 = 'a/'
source_folder2 = 'b/'
target_folder = 'Image_Merged/'
n = len(source_folder1)+1
for img_no in range(1,n+1):
img1 = (source_folder1+str(img_no)+".jpg")
img2 = (source_folder2+str(img_no)+".jpg")
images = [Image.open(x) for x in [img1, img2]]
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(target_folder+"/target_folder_"+str(img_no)+".jpg")
添加回答
举报