Given a known number of images with the same width to height ratio and dimensions, is there an algorithm that determines the best way to present them in a screen whose resolution may vary? Aka arrange them single page or double page.
For example, to determine if you can present two images on the screen or, given the width/height, to “detect” that only one would look better. To see if it’s better to have them fit on width, with some blank space above and/or below them, or to fit on height, with blank space on the left/right.
I have made some attempts to determine such an algorithm of my own, but I’m not completely satisfied and I was hoping there might be a better solution or maybe some advices.
Unfortunately, it’s not as simple as “width > height => two images otherwise one image”, as I found out.
Summed up, right now I do all my calculations based on the image height first and then check if the screen width’s is larger than 1.5 x my image width. Larger means I decrease the height to have two images fit, smaller means I only present one image. Still, I keep getting some undesired results for certain combinations of image sizes / screen resolutions.
If you stumbled upon the same problem and have some code or tips to spare, it would be greatly appreciated.
P.S. As you may figure out, this is about presenting a magazine.
[edit] I forgot to mention that I’m using javascript (vanilla, no plugins/frameworks) for the coding
To answer my own question, it seems there isn’t such an algorithm or at least I wasn’t able to find one. The kd-tree suggested is a waaaaaaaaaaaaay too complicated overkill solution to be practical.
In the end, I settled for the one I came up with myself:
Here is a vanilla javascript implementation