Yesterday I decided to make a program for creation a collage from images.
I've selected the next important input parameters: images list, output resulting collage image, width of resulting collage and the value of images' initial height (this value is approximate and will change, to fit the line of images in given width).
I've chosen the next algorithm:
1) Try to add images (resized to initial height) one by one to the first line:
And when the sum of their widths will go beyond the width value, start the next line.
2) After all images were added to the line, need to fit their size to width value. Here the height of images in the line will be changed from initial height.
3) Resize images to fit the width in all lines.
4) If one of the lines will contain only one image - need to repeat all steps from the beginning again, reducing the initial height value, to compact lines and to find a place for mentioned "alone" image.
I've also added shuffle of images, to get different collages each time.
The result of the program is the next:
Source code for collage maker is available on my github: https://github.com/delimitry/collage_maker
It's written in Python and uses PIL (Python Imaging Library).