I would make a grid, or pre-built table that has one row, and how ever many images acrross you want. Then when you get your images, get a count, and dynamically add rows, using the index of the image placing it into the index of the cell/td. Would be a good route, until you maybe find a library for it if there is one. Though, sometimes, if it isn't a huge "reinventing the wheel" type of snippet, there are some benefits to writing your own code for it. :) Hopefully that helps.
By the way, jQuery Masonary, and Responsive Photo Grid are some libraries you could look into to. Here is a related post for you:Mosaic Grid gallery with dynamic sized images