Google's new image search results page

Google's new image search results page

I am intrigued by the way it shows rows of images which are neatly justified, left AND right sides.   I was trying to figure out how they manage to do that so I could incorporate it into an image scroll of my own.

Do you suppose they are cleverly pre-selecting images for each row so they fit nicely or is there some sleight of hand going on with how they size them?  Every so often I DO see thumbs that have a few pixels cropped off the sides.  What I DON'T see are images where they've been cropped severely enough so as to be immediately noticeable in the thumbnail (such as a simple case of a CSS 'background-position: 50% 50%' and letting what spills over just be hidden)

They DO vary in row height a few pixels +/-, so they must be tweaking the total width of all images a bit to fit them perfectly in a row.  And they either have n or n+1 images across each from from what I've seen.  

So, in a world where I don't have a virtually-unlimited supply of images to pick from and fit nicely, do you suppose there's a practical solution to doing this myself?