So justified photo layouts are done by turning layout into a graph-traversal problem, and that approach is based on a dynamic line-breaking algorithm Donald Knuth and made for laying out text in TeX.
From: https://medium.com/google-design/google-photos-45b714dfbed1