Pro-tip: if you express your layout as a tree composed of horizontal split, vertical split and images then you can come up with a general linear system of equations that you can feed to any solver (basically just inverting a matrix) to get the layout.<p>I'm working on a blog post about it. In the meantime you can look at other image layouts I wrote about: <a href="http://blog.vjeux.com/category/image/" rel="nofollow">http://blog.vjeux.com/category/image/</a>
We did a similar thing a while back when we had a similar layout on an early news site. Then I used math to make our code smarter instead.<p>Rather than having lots of weird image sizes dictate my layout, I decided to have my weird layout dictate my image sizes. The result was this:<p><a href="https://www.mashape.com/stremor/automatic-image-crop-and-resize" rel="nofollow">https://www.mashape.com/stremor/automatic-image-crop-and-res...</a><p>Yes. This really does crop images for any aspect ratio. Automatically. Yes, if you try and make a picture that is just your face be 1080 tall and 90 wide it will likely choose just your nose. What do you want it to do in that scenario? this is meant for taking 4:3 and making them square, or 16:9 and making them 9:16, not for taking 16:9 and making it 1:4. But it will try its darnedest.
Being able to come up with elaborate equations to draw a layout is a smart way to tell the browser how to dynamically resize and position a set of elements. It has, for example, helped me design custom "Pinterest-like" layouts.<p>Keep in mind though that some simple techniques that require(d) JavaScript can (now) be achieved with CSS only. I'm thinking about how to center vertically and horizontally a fix-sized box, or how to make an element take up the whole height of the viewport (without messing with the scrolling). I myself used to rely upon JavaScript calculations to retrieve dynamically the viewport's height, whereas the browser's rendering engine could actually achieve it way more efficiently and with only a couple of lines of CSS code.
Interesting write-up. I'm assuming there is a fixed number of images to fit into the layout which makes the problem a lot easier. Otherwise a bin-packing approach might be warranted.<p>Somewhat related, I came across an interesting method to resize images called "seam carving". It uses a dynamic programming approach to remove rows or columns that seem uninteresting. The end result is that the important parts of the image are retained when the image is resized. The wikipedia page is fairly good: <a href="http://en.wikipedia.org/wiki/Seam_carving" rel="nofollow">http://en.wikipedia.org/wiki/Seam_carving</a> There are nice demos on Youtube as well: <a href="http://www.youtube.com/watch?v=6NcIJXTlugc" rel="nofollow">http://www.youtube.com/watch?v=6NcIJXTlugc</a> Now imagine doing this on the front-end (might be possible now in real-time) and the layouts this would allow!
Those equations look straight out of a book on how not to code layouts. If you need to tweak it to add an extra slot in the bottom right one day, you'll have to re-work on the entire set of equations. The constraints based method they talk about after is much better, though.