I have two different folders a and b. The 'a' folder contains images of the format a_i.jpg (where i = 1 to N). The 'b' folder contains images of the format b_i.jpg. I want to merge these images taking a_1 and merging it with b_1, a_2 with b_2, .... a_N with b_N and then store the new image dataset in a different folder that contains 'N' merged images of the same format and n_i.jpg.
NOTE: I made sure that all the images are of the same size.
With this code I'm able to merge singular files, but how do I loop over the entire folders as mentioned above?
images = [Image.open(x) for x in ['in.jpg', 'tulips.jpg']]
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('new2.jpg')