Old Artstation-like Grid Layout

Hey! I’m looking for some pointers on how to achieve a grid layout similar to the one Artstation used to have, where grid items can be dynamically sized to be 2x2 or 3x3 of a normal item size. Other items would then be reordered in the grid so as to not leave blank spaces. I want to apply this to a collection list, so another requirement is that a collection item’s size is determined by a CMS Option.

Below, an example of what I’m talking about. Taken from a wayback machine snapshot of Artstation’s grid: