Gallery Code
The code for rendering user galleries is very complex. Some details here in case I forget them (as has happened before...)
Dynamic resizing
The gallery code notes the aspect ratio of each image in a given gallery, and uses this to arrange images in neat rows of fixed width by adjusting the row height.