The CSS for this is indeed tricky. I figured out this layout 5 years ago in the v1 and forgot how it works, just took it over as it looks good. The key is that not all rows are exactly the same height. There are small differences that allow photos to fit horizontally.
I also tried the vertical masonry layout, which looks good, but makes no sense if your photos have a chronological order...
The magic happens here: https://github.com/SimplePhotoGallery/core/blob/a3564e30bcb6...