import Image
import numpy as np
import os as os


# merge two pngs to one png side by side

img1=Image.open('img1.png')
img2=Image.open('img2.png')


new_im=Image.new("RGB",(img1.size[0]*2,img1.size[1]))

new_im.paste(img1,(0,0))
new_im.paste(img2,(img1.size[0],0))

new_im.save("merged_images.png")


# merge pngs to on pdf, one image per side
path='images/'
plot_list = [1 for fn in os.listdir(path) if fn.endswith('.png')]
for q in plot_list: file_list=file_list+"%s%s " %(path,q) 
os.system("pdftk %s cat output merged_plots.pdf" %file_list)


# now make the above pdf to a collection with 4x3 plots per page
os.system("pdfnup --nup 4x3 --outfile collection_plots.pdf merged_plots.pdf")
