Simple grid-layouter

Written by  on September 22, 2015 

How to layout a given number of thumbnails N of picW x picH into m columns and n rows in a given page (pageW x pageH) so that the “to be applied” scale is maximal? All thumbnails yield the same dimensions, reordering is not allowed, rotation neither. If the chosen scale is maximized, then the result will have the biggest possible thumbnails. I need this for the contactSheet-script, because currently it uses fixed column-sizes and I don’t want to figure this out manually each time the wanted page- or thumbnail-size or the amount of thumbnails changes.

layout

I am aware, that this is some kind of well known bin-packing problem, but just after implementing the very first naive approach I figured out that there is maybe(?) no closed equation possible: just iterating over all possible cases. Maybe I missed something, but the current approach would look like the following. I will move this from C++/Qt to sh soon, because this will become part of contactSheet-script which I apply to every set of scanned film 😉

By the way: the sketch has been done with draw.io, because I stopped using Dia

Category : C++

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.