Why this question?
I have been doing research for ~2 months for this but couldn't find anything relevant so finally asking a question here.
Problem Statement
I'm looking to place a set of images with different sizes in a fixed-width container just like Canva does-
This is for sure not a masonry layout because here, Canva is bifurcating images into different rows based on some (?) calculation. What I was able to achieve is this-
This I achieved using https://masonry.desandro.com/ JS library, but it has its own limitations.
My Research
Based on my ~2 months of research, what Google has been telling me is that it's a masonry layout or it's 2D Bin Packing problem but I feel, it's not.
Canva is doing probably something very simple & intuitive (like explained here https://stackoverflow.com/a/14551767/2405040).
Libraries I found and tried
- https://masonry.desandro.com/
- https://spope.github.io/MiniMasonry.js/
- https://github.com/desandro/masonry
- https://isotope.metafizzy.co/
- https://isotope.metafizzy.co/layout-modes/masonry.html
- https://github.com/bigbite/macy.js
Links & blog posts
- https://codeincomplete.com/articles/bin-packing/demo/
- https://github.com/jakesgordon/bin-packing/
- https://github.com/olragon/binpackingjs
- How is 2D bin packing achieved programmatically?
Final Question
Is that something very unique, or is it some calculation? How can I achieve this Canva like layout programmatically?