After creating my gallery of good looking girls, a buddy of mine sudgested to create a screen saved that would query that gallery, fetch couple images and display them. The idea was good, how ever after cheking out picasa program I found aneat program that created a mosaic collage of your photos. And not a regular collage of random photos, but place them perfectly on the given canvas size where each one is shown with out tilting any images and each one is in different size and aspect ratio while still fitting in perfectly. I was simply amazed and decided to implement that into my gallery, however it was not as simple as it looked.
A picture collage in general is ery simple to create. You have a set of images, a canvas and a random number generator. Then you put that togeather and you get a random thrown pictures on a surface. It is like taking a whole bunch of photos and throwing them on the floor. Of course the canvas maybe different shapes, but the same deal applies.
A mosaic picture collage can be of two types from what I seen.
One kind is where you have them neatly aligned in same sized boxes or simply a grid. Some times one picture may take up two boxes in that grid. This method I have tried to put into algorithm and did not like the outcome. The images do appear random on the given canvas but a strong pattern can be seen that a grid was used. Additionally since the aspect ratio on the grid is fixed, some images maybe heavily cropped. With this grid method one can create a collage where a huge image in in the middle with a border made of small ones for instance.
Second method creates a picture collage where every picture is positioned perfectly on the canvas and each image is different size and aspect ration. The algorithm to create such a collage is not as simple. You are given a number of random images, each one is different size and different aspect ratio. Have fun placing them on a canvas anf filling up every bit of space with out braking anything.
After observing how picasa does its mosaic collage, things got very easy. For one, Instead of asking to create a collage out of specific images, my script would first create a random collage outline and then find pictures for it, easy come easy go. No. That is not where it ends, the main part of the script is to intake a set of images and do a pixel perfect placement in a row of pictures to fill a canvas. After that is accomplished, you now have the ability to fill an endless horizontal or vertical line on the canvas. With this we can easily create several horizontal lines of images or vertical. The next step would be to divide the canvas into several section based on how many images you want to stuff into it. Decision making while splitting the canvas into sections must account for how many images will go where and what aspect ratios should be forced or not forced into the zone. Finally the sections are created and all that’s left is to run the horizontal/vertices fill algorithm into each block. Some bias could be seen to image selection, for instance a landscape block with four preferred images will randomly select four portrait images. However if the preferred number is two, then the script will likely get 2 landscape pictures out of the database. The final algorithm must randomly pick how many of landscape and portrait type images to use in giver blocks.
To sum up. We get an order for a mosaic collage of 10 images on a certain sized canvas. The script will divide the canvas into blocks that would house one to four images aligned vertically or horizontally. And run a cropping algorithm to randomly picked images out of the database to fit into those blocks pixel perfect.